I need some advice. I need to get data from API to display it on my application. The API is working both through Postman or through the browser, but when I upload the same code to the server, my API response returns NULL.
Here is the response I am getting with POSTMAN:
And here is the code I am using:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.instagram.com/myexcellentuser/?__a=1');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$file_data = json_decode(curl_exec($ch));
curl_close($ch);
var_dump($file_data);
And here is what this same code returns on the app hosted on a server:
I would be extremely grateful for the advice!
Thanks!
Related
The purpose of this CURL is to generate a token for the user. If the token is returned correctly, then the user can be able to access all the menus. If not, the user will get a logout from the application.
$ch = curl_init();'
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, 'Proxy IP');
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$result = curl_exec($ch);
What I am missing here??
NOTE: The server I am connecting to is in the AWS cloud, and we already have a server which is outside the cloud, and the curl is working fine and the generated token is receiving. I am not sure what the problem here is.
I am a beginner in PHP and I am trying to put POST data using cURL. I tried in Postman my data and it returns
but when I execute this code below which I found here in StackOverflow response returns me a 307 Temporary Redirect.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://mycustomURL.com/api/v1/login" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"loginid":"test",
"password":"111111"
}' );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/raw'));
$result=curl_exec ($ch);
var_dump($result);
Can you help me what is the problem? Thank you.
To make cURL follow a redirect just add this line:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
for more info see php.net curl
When I call the YouTube V3 API for a list of videos by playlist ID, I get the correct results when calling the API via Postman, but outdated results (missing today's newly uploaded video) when calling the API via cURL with PHP. I think maybe I am getting cached results with cURL but I don't know why that would be the case.
My PHP code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=$playlistId&key=$api_key&maxResults=50");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Cache-Control: no-cache"
));
$json = curl_exec($ch);
curl_close($ch);
My Postman request:
Type: GET
URL: https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=(playlist-id)&key=(api-key)&maxResults=50
When getting the Google site in cURL PHP I get the old Google page (The one with the blackbar and weird buttons). So is there a way to get the Google as it appears on google.com? My code:
function file_get_contents_curl($url, $proxy) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo file_get_contents_curl('https://www.google.com/', 'proxy:8080');
Thanks, if there is no way I am ok with the weird looking Google.
I want get Authentication Token of D&B API version 2 REST methodology
http://developer.dnb.com/docs/2.0/common/authentication-process
Sample Request - Get New Token
POST https://maxcvservices.dnb.com/rest/Authentication
x-dnb-user: P2000000FD4A9DE85D848229E03507C8
x-dnb-pwd: volcano
I have already tested these credentials on Chrome Extension (Advanced REST Client), they worked fine.
So now How can I achieve this using PHP code, Please help
Thanks
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://maxcvservices.dnb.com/rest/Authentication');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('x-dnb-user: P2000000FD4A9DE85D848229E03507C8','x-dnb-pwd: volcano'));
$param_array = array();
$param_query_string = http_build_query($param_array);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param_query_string);
$response = curl_exec($ch);
I had a discusstion with DnB technical team and they sent me .NET example code, I learned code and applied same logic using PHP and it worked finally.