2010-05-17 90 views
3

在PHP中,我試圖使用圖表api發佈狀態到我們的Facebook粉絲頁面,儘管下面的facebook給出的信息,下面的代碼似乎並沒有更新狀態。通過Facebook的圖表發佈狀態api

這是代碼;

$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

什麼打印'$ result'顯示? – ceejayoz 2010-05-17 16:23:31

+0

$結果爲空 – 2010-05-17 16:27:18

+1

您的意思是使用'$ xPost ['access_token'] =「{key}」;' 而不是'$ xPost ['access_token'] =「{$ key}」;' – Jayrox 2010-06-02 23:19:01

回答

0

它似乎「CURLOPT_SSL_VERIFYPEER」應設置爲0;

e.g. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 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

只是另一個快速的問題。上述命令返回一些值,如「{」id「:」1347466624_1603672123512「}」。有什麼辦法可以禁用這個輸出嗎? – ericbae 2010-09-20 04:46:33

+1

我知道這是在2010年發佈的,但如果有人用同一個問題解決了這個問題,[答案在這裏](http://stackoverflow.com/a/1918394/1337431) – 2012-04-27 10:49:22

0

要張貼在牆上的照片的相冊照片,你需要知道這張專輯的專輯ID(AID),並把它添加到這樣 附件我離開我的代碼:

$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); 
相關問題