在Linux服务器上使用curl获取facebook的访问令牌
我在尝试使用 cURL 从 Linux 服务器上的 Facebook 获取访问令牌时遇到问题。在我的 Windows 机器上,当我在 XAMPP 下运行 PHP 时一切正常,但在 Linux 中却不行。
我已在 Linux 服务器上安装了 cURL,现在尝试使用它,但它不返回任何信息。
我的代码如下:
$url = "https://graph.facebook.com/oauth/access_token?client_id=278313225526998&redirect_uri=thejunction.africanbank.net/baobab/baobab.php&client_secret=$app_secret&code=$code";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: graph.facebook.com'));
$access_token = curl_exec($ch);
curl_close($ch);
echo "access is: ".$access_token;
有人可以让我知道我在这里可能做错了什么吗?它给了我错误:
An error occured while fetching the URI
我也尝试使用
$url = 'http://www.stackoverflow.com'; //curl脚本获取给定url的内容 $ch=curl_init(); // 设置目标url curl_setopt($ch, CURLOPT_URL,$url); // 像 Firefox 一样请求 curl_setopt($ch, CURLOPT_HTTPHEADER, Array("用户代理: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); curl_setopt($ch, CURLOPT_NOBODY, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $结果=curl_exec($ch); 卷曲关闭 ($ch); echo "结果是".$result;
它给了我一个错误
An error occured while fetching the URI. Please retry.
,并且在我的 php.ini 文件中启用了curl,请参见图片
可能是什么问题?请帮我。
谢谢 唐纳德
I'm having a problem trying to use cURL to get the access token from Facebook on my Linux server. On my Windows machine everything works fine when I'm running PHP under XAMPP, but not in Linux.
I have installed cURL on my Linux server and am now trying to use it, but it doesn't return any information.
My code is as follows:
$url = "https://graph.facebook.com/oauth/access_token?client_id=278313225526998&redirect_uri=thejunction.africanbank.net/baobab/baobab.php&client_secret=$app_secret&code=$code";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: graph.facebook.com'));
$access_token = curl_exec($ch);
curl_close($ch);
echo "access is: ".$access_token;
Can someone please let me know what I might be doing wrong here? It gives me the error:
An error occured while fetching the URI
I also tried using
$url = 'http://www.stackoverflow.com'; //curl script to get content of given url $ch = curl_init(); // set the target url curl_setopt($ch, CURLOPT_URL,$url); // request as if Firefox curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); curl_setopt($ch, CURLOPT_NOBODY, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result= curl_exec ($ch); curl_close ($ch); echo "result is".$result;
and it gives me an error
An error occured while fetching the URI. Please retry.
and in my php.ini file curl is enabled, please see the picture
What might be the problem guys? please help me.
Thanks
Donald
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的redirect_uri 错误。它应该
,因此更改
为
Your redirect_uri is wrong. It should be
so change
to