【问题标题】:POST to Facebook page via CURL通过 CURL 发布到 Facebook 页面
【发布时间】:2012-11-08 17:00:27
【问题描述】:

我已经设置了一个脚本来通过 PHP 将新闻发布到我的 Facebook 页面

过去 2 年一直有效

现在,不知不觉就停止了工作。

我正确地得到了access_token,但第二部分返回了这个错误

{"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1}}

这里是代码

$url = "https://graph.facebook.com/oauth/access_token";
$postString = "client_id=KEY&client_secret=SECRET&type=client_cred";
$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);
$access_token = str_replace( "access_token=", "", curl_exec($curl) );


$titolo = 'Test';
$link_pulito = 'test.html';
$testo_fb = 'Test';

$attachment =  array(
        'access_token' => $access_token,
        'message' => 'MESSAGE',
        'name' => 'test',
        'link' => 'http://www.test.com/workshop/',
        'description' => 'test test test',
        'picture'=>'http://www.test.com/77818763a19937bdd82b25f26cef2522.jpg'
        );

// set the target url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/MYPAGE/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);  //to suppress the curl output 

$result= curl_exec($ch);
curl_close ($ch);

【问题讨论】:

  • 您确定您获得了正确的访问令牌吗?您只是假设 curl_exec() 调用有效并且没有返回布尔值 false。
  • 是的,我可以回显 access_token 并查看它

标签: php facebook post curl


【解决方案1】:

Facebook 改变了租赁代币的方式。 请使用来自https://github.com/facebook/facebook-php-sdk的facebook PHP SDK

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2010-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-07
  • 2012-09-13
  • 2016-12-16
  • 1970-01-01
相关资源
最近更新 更多