問題描述
我已經創建了一個應用程序,現在我想使用新的 Graph API 在我的一個朋友墻上發布一條消息.這能行嗎?
I have created an app, and now i want to post a message on one of my friends wall with use of the new Graph API. Is this do-able?
我已經在使用 oAuth 和 Graph-api 來獲取我所有朋友的列表.http://developers.facebook.com/docs/api 上的 API 告訴我 cURLhttps://graph.facebook.com/[userid]/feed 閱讀feed,但它也告訴我如何發布消息:
I am already using oAuth and the Graph-api to get a list of all my friends. The API at http://developers.facebook.com/docs/api tells me to cURL https://graph.facebook.com/[userid]/feed to read the feed, but it also tells me howto post a message:
curl -F 'access_token=[...]' -F 'message=Hello, Arjun. I like this new API.' https://graph.facebook.com/arjun/feed
這當然不行!我不知道為什么..
Ofcourse this doesn't work! And I can't find out why..
這是我的 PHP 代碼:
Here are my PHP-code:
require_once 'facebook.php'; // PHP-SDK downloaded from http://github.com/facebook/php-sdk
$facebook = new Facebook(array(appId=>123, secret=>'secret'));
$result = $facebook->api(
'/me/feed/',
array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..')
);
這段代碼沒有拋出任何錯誤,而且我知道我的 access_token 是正確的(否則我無法運行 $facebook->api('/me?access_token='.$this->access_token); 來獲取我的用戶對象.
This code does not throws any error, and I know my access_token are correct (otherwise i could't run $facebook->api('/me?access_token='.$this->access_token); to get my userobject.
有沒有人使用 Graph-api 成功發布消息?那么我需要你的幫助!:-)
Have anyone out there sucsessfully posted a message using Graph-api? Then i need your help! :-)
推薦答案
好的,我終于解決了這個問題.感謝 phpfour 的幫助:-)
Okay, I finally solved this. Thanx to phpfour for your help :-)
首先:我的連接 url 看起來像這樣(帶有publish_stream"):
First: My connection-url looks like this (with "publish_stream"):
$connectUrl = $this->getUrl(
'www',
'login.php',
array_merge(array(
'api_key' => $this->getAppId(),
'cancel_url' => $this->getCurrentUrl(),
'req_perms' => 'publish_stream',
'display' => 'page',
'fbconnect' => 1,
'next' => $this->getCurrentUrl(),
'return_session' => 1,
'session_version' => 3,
'v' => '1.0',
), $params)
);
第二;我試圖通過
$result = $facebook->api(
'/me/feed/',
array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..')
);
但正確的做法是多包含一個參數('post'):
But the correct way to do this is include one more parameter ('post'):
$result = $facebook->api(
'/me/feed/',
'post',
array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..')
);
這篇關于如何使用 FB Graph 在提要(墻)上發布消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!