如何使用应用程序访问令牌通过publish_stream而不是offline_access发布到Facebook用户的朋友墙
publish_stream 的文档写道:“使您的应用能够将内容、评论和点赞发布到用户的流和用户朋友的流中。有了此权限,您可以随时将内容发布到用户的源,而不需要进行离线访问。 ”
所以工作流程是这样的:
FB.login(),具有publish_stream范围,如下所示:
FB.login(函数(响应){ if (response.authResponse) { FB.api('/me/permissions', 函数 (权限) { if (permissions.data[0].publish_stream == 1) { //用户现在已将publish_stream授予此应用程序 } }); } }, { 范围: 'publish_stream' });
使用C# Facebook SDK使用应用程序的访问令牌发布到该用户朋友的留言墙上。
var client = new FacebookClient(FacebookAppId, FacebookAppSecret); // 建造墙柱 动态参数 = new ExpandoObject(); 参数.message = facebookDeliveryQueueItem.MessageBody; // 用户留言 // 发布到墙上 client.Post(facebookRecipientId + "/feed", 参数);
这返回:
{"error":{"message":"(#200) The user hasn't authorized the application to perform this action","type":"OAuthException"}}
但是!如果我尝试使用此代码发布到我自己的墙上,它就可以正常工作。
如果用户向我的应用程序授予publish_stream,我就可以使用应用程序访问令牌(您可以通过向 https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID_HERE&client_secret=APP_SECRET_HERE)在该用户的墙上发布 - 但不是该用户朋友的墙上墙。
那么 Facebook 文档中的“以及用户朋友的信息流”部分是谎言还是我做错了?那里有大量的错误信息。
Documentation for publish_stream reads: "Enables your app to post content, comments, and likes to a user's stream and to the streams of the user's friends. With this permission, you can publish content to a user's feed at any time, without requiring offline_access."
So the workflow is thus:
FB.login() with publish_stream scope like so:
FB.login(function (response) { if (response.authResponse) { FB.api('/me/permissions', function (permissions) { if (permissions.data[0].publish_stream == 1) { //user has now granted publish_stream to this application } }); } }, { scope: 'publish_stream' });
Use the C# Facebook SDK to post to this user's friend's wall using the application's access token.
var client = new FacebookClient(FacebookAppId, FacebookAppSecret); // Build the wall post dynamic parameters = new ExpandoObject(); parameters.message = facebookDeliveryQueueItem.MessageBody; // user message // Post to the wall client.Post(facebookRecipientId + "/feed", parameters);
This returns:
{"error":{"message":"(#200) The user hasn't authorized the application to perform this action","type":"OAuthException"}}
However! If I attempt to use this code to post to MY OWN wall, it works just fine.
If a user grants publish_stream to my application, I can then use the the APPLICATION access token (you get this by issuing a GET to https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID_HERE&client_secret=APP_SECRET_HERE) to post on that user's wall -- but NOT to that user's friend's wall.
So is the "and to the streams of the user's friends" part of the Facebook documentation a lie or am I doing it wrong? There is a ton of misinformation out there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
<罢工>
您应该在发出请求之前显式指定
access_token
,如果省略,则使用当前用户的access_token
。在调用
client.Post< 之前添加此内容/code>
文档是正确的(在本例中)。一旦用户使用应用程序
access_token
授予您publish_stream
权限,您就可以在用户及其朋友的留言板上发帖(无需需要请求offline_access< /code>!) 尊重墙主人的喜好。一些用户设置隐私设置以拒绝特定用户/应用程序甚至其他任何人发布内容。
确保您可以使用 http://facebook.com 在特定朋友(与您有问题的朋友)墙上发帖 并使用Graph API Explorer工具(提供应用程序
access_token
一定)。You should explicitly specify
access_token
before issuing request, if you omit itaccess_token
of current user is used.Add this before call to
client.Post
The documentation is correct (in this case). You can post on user's and his friends wall once user granted you
publish_stream
permission using applicationaccess_token
(without need to ask foroffline_access
!) with respect of wall owner preferences. Some users set privacy settings to deny specific users/application or even anyone other to post content.Ensure you can post on that specific friend (one you have issue with) wall using http://facebook.com and using Graph API Explorer tool (providing application
access_token
for sure).