Php Curl returns data on local machine but bool fa

2019-08-02 01:30发布

I am trying to get facebook access token

But the url when executed from browser and local machine php script returns true data values. However, when i run the same script from server, it fails and shows bool(false)

the url

   $token_url = "https://graph.facebook.com/oauth/access_token?"
    . "client_id=".$config['appId']."&redirect_uri=" . urlencode($config['callback_url'])
    . "&client_secret=".$config['secret']."&code=" . $_GET['code'];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $token_url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $response = curl_exec ($ch);

    var_dump($response);

Other urls work on the server.

What is wrong here ?

3条回答
家丑人穷心不美
2楼-- · 2019-08-02 02:01

I have been given to understand from an upvoted answer on one of the other questions that my server Hostinger (free) does not allow connecting to Facebook SDK !!!

I am moving to a paid server !

查看更多
放荡不羁爱自由
3楼-- · 2019-08-02 02:03

Try to check curl_error

curl_error — Return a string containing the last error for the current session

That may help finding what was wrong .

查看更多
走好不送
4楼-- · 2019-08-02 02:09

You should check at the curl error instead of only looking at the curl_exec result:

PHP 4 >= 4.0.3, PHP 5, PHP 7) curl_error — Return a string containing the last error for the current session

Try this:

if(curl_exec($ch) === false) {
    echo 'Curl error: ' . curl_error($ch);
} else {
    echo 'Operation completed without any errors';
}


curl_close($ch);

UPDATE

Try setting this:

'curl' => [ CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4]

For more details check here

查看更多
登录 后发表回答