【问题标题】:Facebook Authentication using cURL (php)使用 cURL (php) 进行 Facebook 身份验证
【发布时间】:2010-10-06 00:42:33
【问题描述】:

我正在尝试使用 cURL 进行 facebook 身份验证,这就是我所拥有的:

        $url = "https://graph.facebook.com/oauth/access_token";
        $postString = "?client_id=$client_id&redirect_uri=$redirect_uri&client_secret=$client_secret&code=$code";
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_FAILONERROR, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        //curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
        $response = curl_exec($curl);

但每次它只返回 false。

我对使用 cURL 很陌生,所以我可能会犯一些初学者的错误,但我很困惑为什么这根本不起作用。

任何帮助将不胜感激!

【问题讨论】:

  • 解决了,这是一个 ssl 问题,加上我的 $postString var 中的错字(开头的“?”)。

标签: php facebook curl


【解决方案1】:

这可能太明显了,可能是一个错字,但是:

//curl_setopt($curl, CURLOPT_POST, 1);

应该取消注释。

【讨论】:

  • 我只是在测试 GET 和 POST 以查看它是否有所不同,我碰巧在复制粘贴代码之前刚刚测试了 GET :) 无论如何感谢您的回答!
  • 如果我是你,我会这样调试:FAILONERROR 应该被取出,或者评论。和'?在$postString 中取出(我相信)。它会给出任何形式的响应,还是$response 为空?
【解决方案2】:

去掉“?”从您的帖子字符串的开头......应该可以解决它!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多