简体   繁体   English

用户如何向我的应用授予users_posts权限?

[英]How can users grant my app the users_posts permission?

I want to create a PHP application using the Facebook PHP SDK that pulls a users posts from the users wall and displays it as a feed on the users home page. 我想使用Facebook PHP SDK创建一个PHP应用程序,该应用程序从用户墙上拉出用户帖子,并将其作为提要显示在用户主页上。 According to the Graph API https://graph.facebook.com/{user-id}/feed is what I should request: 根据Graph API https://graph.facebook.com/{user-id}/feed是我应该要求的:

However, the API documentation says: 但是,API文档说:

Your app needs user_posts permission from the person who created the post or the person tagged in the post. 您的应用需要获得帖子创建者或帖子user_posts权限。

I haven't figured out how to get the user to grant this permission, and currently the following request 我还没有弄清楚如何让用户授予此权限,目前以下请求

https://graph.facebook.com/userid/feed?access_token=123|abc-def&limit=4&locale=en

results in error 404 (as one would expect). 导致错误404(正如人们期望的那样)。

There is a lot of (outdated) tutorials about how to create an app to pull a user feed from Facebook, but none of them tell you how to get the users_posts permission from the user that owns the feed. 有很多(过时的)教程,介绍如何创建应用程序以从Facebook提取用户供稿,但是没有一个教程告诉您如何从拥有供稿的用户那里获取users_posts权限。 It looks like you didn't need this before, but Facebook has recently tightened their privacy protection and the old ways no longer work. 看来您以前不需要此功能,但是Facebook最近加强了对它们的隐私保护,并且旧的方式不再起作用。

How can users grant my app the users_posts permission? 用户如何向我的应用授予users_posts权限?

(I am using my own user to test this, so this is not about coaxing the user to grant the permission - it is about how you code the app so that the user actually can do this.) (我正在使用自己的用户进行测试,因此,这并不是要诱使用户授予许可,而是要对应用进行编码,以便用户实际可以执行此操作。)

I suggest using the JS SDK for login, because it is a lot easier. 我建议使用JS SDK进行登录,因为它要容易得多。 For example, this is how you authorize users with the user_posts permission: 例如,这是您使用user_posts权限授权用户的方式:

FB.login(function(response) {
    if (response.authResponse) {
        //user just authorized your app
        console.log(response);
    }
}, {scope: 'user_posts', return_scopes: true});

After that, you can just use this to get the posts: 之后,您可以使用它来获取帖子:

FB.api('/me/feed', {limit: 4}, function(response) {
    console.log(response);
});

Source: http://www.devils-heaven.com/facebook-javascript-sdk-login/ 来源: http//www.devils-heaven.com/facebook-javascript-sdk-login/


If you want to login with the PHP SDK, read this: https://developers.facebook.com/docs/php/howto/example_facebook_login 如果要使用PHP SDK登录,请阅读以下内容: https : //developers.facebook.com/docs/php/howto/example_facebook_login

The relevant part from the docs: 来自文档的相关部分:

$permissions = ['user_posts'];
$loginUrl = $helper->getLoginUrl('https://example.com/fb-callback.php', $permissions);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM