在PHP中,我试图使用图形api将状态发布到我们的Facebook粉丝页面,尽管遵循facebook给出的说明,以下代码似乎没有更新状态。
这是代码;
$xPost['access_token'] = "{key}";
$xPost['message'] = "Posting a message test.";
$ch = curl_init('https://graph.facebook.com/{page_id}/feed');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xPost);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_CAINFO, NULL);
curl_setopt($ch, CURLOPT_CAPATH, NULL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$result = curl_exec($ch);
有谁知道为什么这段代码不起作用? access_token是正确的。
答案 0 :(得分:3)
$url = "https://graph.facebook.com/ID_HERE/feed";
$ch = curl_init();
$attachment = array( 'access_token' => 'your token',
'name' => "Title",
'link' => "www.google.com",
'description' => 'description here',
);
curl_setopt($ch, CURLOPT_URL,$url);
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);
$result= curl_exec($ch);
curl_close ($ch);
答案 1 :(得分:0)
似乎“CURLOPT_SSL_VERIFYPEER”应该设置为0;
e.g. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
答案 2 :(得分:0)
要在Wall相册的相册上发布照片,您需要知道此相册的相册ID(辅助)并将其添加到附件中 我留下了我的代码:
$url = "https://graph.facebook.com/" . $this->getPageId() . "/photos";
$attachment = array(
'access_token' => $this->getAccessToken(),
'source' => '@' . $source,
'aid' => $aid,
'message' => $message,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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);
ob_start();
curl_exec($ch);
$this->setjsonResult(ob_get_contents());
ob_end_clean();
curl_close($ch);