如何使用 FB Graph 在 feed(墙上)上发布消息
我已经创建了一个应用程序,现在我想使用新的 Graph API 在我的一个朋友的墙上发布一条消息。这可行吗?
我已经在使用 oAuth 和 Graph-api 来获取我所有朋友的列表。 http://developers.facebook.com/docs/api 上的 API 告诉我 cURL https://graph.facebook.com/[userid]/feed 阅读feed,但它也告诉我如何发布消息:
curl -F 'access_token=[...]' -F 'message=Hello, Arjun. I like this new API.' https://graph.facebook.com/arjun/feed
当然这不起作用!我不知道为什么..
这是我的PHP代码:
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); 来获取我的用户对象。
有人使用 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?
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..
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..')
);
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.
Have anyone out there sucsessfully posted a message using Graph-api? Then i need your help! :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
好吧,我终于解决了这个问题。感谢 phpfour 的帮助:-)
第一:我的连接 URL 看起来像这样(带有“publish_stream”):
第二;我尝试通过以下方式发布到 facebook
但正确的方法是再包含一个参数('post'):
Okay, I finally solved this. Thanx to phpfour for your help :-)
First: My connection-url looks like this (with "publish_stream"):
Second; I tried to post to facebook via
But the correct way to do this is include one more parameter ('post'):
您需要“publish_stream”扩展权限才能写入提要。以下是它们的完整列表: http://developers.facebook.com/docs/authentication/权限。
为了获得扩展权限,请通过以下方式获取授权令牌:
You'll need the "publish_stream" extended permission in order to write to the feed. Here is a complete list of them: http://developers.facebook.com/docs/authentication/permissions.
In order to get the extended permission, get the authorization token in this way:
正如链接所示: 输入链接此处描述
As the link says: enter link description here
澄清一下,这里的“post”是指 HTTP 方法,如 GET/POST 中。
请参阅 https://github.com/facebook/php-sdk/ blob/master/src/base_facebook.php :
受保护函数_graph($path, $method = 'GET', $params = array())
To clarify, 'post' here refers to the HTTP method, as in GET/POST.
See https://github.com/facebook/php-sdk/blob/master/src/base_facebook.php :
protected function _graph($path, $method = 'GET', $params = array())
除了 chf 之外,
发帖后:
我得到的回复是:
不知道哪个是
access_token
、client_secret
或 codeIn addition to chf,
After posting:
I got the response:
no which one is
access_token
,client_secret
or code这是获取访问权限的旧方法。在 GRAPH 中,我首先生成了 code 密钥:
现在,当我们有 code 密钥时,我们可以从链接生成 access_token:
但是这个 access_token 会发布您的消息作为用户而不是应用程序...为什么?!
如果您想在应用程序墙上发布,请使用:
That is old way to get acces. In GRAPH first i generated code key with:
And now when we have code key we can generate access_token from link:
But this access_token post your message as USER not APPLICATION... WHY?!
If you want post on application wall use:
而不是使用下面的代码
使用以下解决方案
Instead of using the below code
Use the following solution