I am creating a Wordpress Plugin that would create a meeting after some transaction but I don't know how to get the token. I made some tests but doesn't seem to work.
Tried doing some post CURL.
$consumerKey = "consumer_key_here";
$url = "https://api.getgo.com/oauth/v2/authorize?client_id={$consumerKey}&response_type=code";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
$test = curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch);
}
print $test;
This should be redirected to the desired redirect url with a response code along the parameter.
To encode these values, open an encoding site and paste in the consumerKey, add a colon (:), and then paste in the consumerSecret. No spaces, no quotes, no brackets. Submit the values and an encoded value is returned that will look something like: ZXhhbXBsZV9jbGllbnRfaWQ6ZXhhbXBsZV9jbGllbnRfc2VjcmV0==.
$ch = curl_init();
if($ch) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$token="for this you need to use documentation ";
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded','Authorization: Basic '.$token,'Accept:application/json'));
$curlulr="https://api.getgo.com/oauth/v2/token";
curl_setopt($ch, CURLOPT_URL, $curlulr);
curl_setopt($ch, CURLOPT_POST, true);
$data = 'grant_type=authorization_code'.
'&code={responseKey}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$rmv_results = curl_exec($ch);
if($rmv_results === false) {
echo('Error performing rmv lookup: '.curl_errno($ch).' - '.curl_error($ch).' (Message ID: '.basename(__FILE__).'-'.__LINE__.')');
} // end if errors
// echo "3";
curl_close($ch);
print_r($rmv_results);
echo ">><br>". $rmv_results;
}
Related
I'm trying to get content of a page through curl call. But I'm getting only an empty array. Here is my code
print_r(get_data('https://www.realestate.com.au/sold/in-9%2f20%3b/list-1'));
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
// the url to fetch
curl_setopt($ch, CURLOPT_URL, $url);
// return result as a string rather than direct output
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// set max time of cURL execution
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
I have also tried different method like file_get_contents function but always getting empty page.
given function is to complicated I think its a copy paste function, as I can see from
return $result; } which is not needed and you should get syntax error.
probably that code will work without that bracket.
I cleared and shortened code, and giving a working and (tested) solution.
NOTE: You can add the code I removed back
$url 'your url';
//Usaqe of function I recomend to use parse_url();
echo get_data($url);
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
I am trying log in a website which has security code for 2 days like you see below.
(By the way, I can get security number from html codes of web page.)
First, I have to connect to website and get the code(254), than post username, password and security number. But there is a big problem. I am getting security number and the page is reloading and the code is changing everytime when I try post to webpage this variables.
Here is my PHP code:
<?php
include('simple_html_dom.php');
$url = "http://example.com/index.php";
$useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
$tmpfname = dirname(__FILE__).'/cookies.txt';
$ch = curl_init(); // GET REQUEST
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$str = curl_exec($ch);
echo $str;
curl_close($ch);
preg_match('~<td><img src="number/(.*?).jpg"></td>~', $str, $securityNo); // I am gettin security number
echo $securityNo[1]; // It print true
$username = "USER";
$password = "PASS";
$postfields = array();
$postfields['UserName'] =$username; // Username
$postfields['Password'] = $password; // Password
$postfields['code'] = $securityNo[1]; // Code
$postfields['LOGIN'] = "LOGIN"; // BUTTON
$curl =curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, $tmpfname);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$ret = curl_exec($curl);
curl_close($curl);
echo $ret;
?>
I printed screen both 'echo $str' (get request) and 'echo $ret' (post request) but there is different 2 codes in screen, not same code printed.
I researched on internet too much, but I got nothing. I can't solve this.
Thanks in advance!
I'm trying to login on website http://www.discogs.com using PHP script and cURL.
I need that to get data from https://www.discogs.com/sell/mywants?ev=wsim - it's a list of offers with items added to want-list. From what I found this list is not available in API.
I have problem with logging in using standard cURL request. Here's my code:
$username = 'myuser';
$password = 'mypassword';
$loginUrl = 'https://www.discogs.com/login';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.urlencode($username).'&password='.urlencode($password));
curl_setopt($ch, CURLOPT_COOKIEJAR, 'c:\cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'c:\tmp.txt');
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch);
return;
} else {
echo "OK";
}
curl_setopt($ch, CURLOPT_URL, 'https://www.discogs.com/sell/mywants?ev=wsim');
$content = curl_exec($ch);
echo $content;
curl_close($ch);
As a result I get login page instead of page with listed offers.
Could you tell me what am I doing wrong?
As I tested, the login page requires posting another field, which is Action.Login in order to make the login request valid.
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.urlencode($username).'&password='.urlencode($password).'&Action.Login=');
Hope this helps.
I am trying to download a file behind a login using cURL and PHP. I am able to connect to the server and login properly using CURLOPT_POST; furthermore, my file downloads properly. However, the contents are corrupted and cannot be opened. On a side note, the file downloads onto the server, how would I use curl to download the file to a users local machine if this tool were ever on a public web server.
// POST data from JSTOR Tool
$username = $_POST['username'];
$password = $_POST['password'];
$start = $_POST['start'];
$end = $_POST['end'];
$loginUrl="https://www.jstor.org/action/doLogin";
print "Hello $username, your articles are downloading.";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.jstor.org/action/doLogin');
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "login=".$username."&password=".$password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie-name');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/var/www/ip4.x/file/tmp');
$answer = curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch);
}
//another request to download the article, but preserves the session
curl_setopt($ch, CURLOPT_URL, 'http://www.jstor.org/stable/pdf/1.pdf');
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
$data = curl_exec ($ch);
print_r($data);
$error = curl_error($ch);
curl_close ($ch);
$destination = "./files/test.pdf";
$file = fopen($destination, "w");
fputs($file, $data);
fclose($file);
print " Did it work?";
Thanks for the help!
I figured it out. I just need curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); in order to prevent redirects from throwing me off.
Using Chrome to inspect the url: http://www.wizards.com/Magic/PlaneswalkerPoints/76954206# I am able to see the url where the JSON data is grabbed from:
Request URL:http://www.wizards.com/Magic/PlaneswalkerPoints/JavaScript/GetPointsSummary/76954206
Running my code:
$user_agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36';
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // times out after 5s
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($json)));
curl_setopt($ch, CURLOPT_POST, 1);
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
// further processing ....
if ($server_output == "OK") {
print_r($ch);
} else {
echo "Boo";
}
Leaves me with a blank page. It's not returning JSON, only the redirect error page.
Is there a certain call I am missing to grab the JSON data?
Try this:
<?php
$url = 'http://www.wizards.com/Magic/PlaneswalkerPoints/JavaScript/GetPointsSummary/76954206';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS, '');
$result = curl_exec($ch);
curl_close($ch);
echo $result;
Output:
{"Result":true,"SessionExpired":false,"Data":[{"Key":"LifetimePoints","Value":6016,"ReplaceElement...