是否可以使用具有读取和发布权限的 Facebook LoginManager 登录?

Is it possible to login with Facebook LoginManager with both Read and Publish permissions?

我正在创建一个 Android 应用程序,您应该可以在其中使用具有读取和发布权限的 Facebook 登录。我用 LoginManager 实现了它并且效果很好。这是我登录 facebook 的方法:

 /**
 * Attempts to log the user into facebook and to get an access token.
 */
private void facebookLogin() {
    callbackManager = CallbackManager.Factory.create();

    LoginManager loginManager = LoginManager.getInstance();
    loginManager.registerCallback(callbackManager, new FacebookLoginCallback());
    loginManager.logInWithReadPermissions(this, Constants.FB_READ_PERMISSIONS);
    loginManager.logInWithPublishPermissions(this, Constants.FB_PUBLISH_PERMISSIONS);
}

一段时间后我注意到虽然这段代码片段启动了两个单独的 Facebook 登录,但当一个完成时另一个仍在后台。如果我只以读取权限登录(或仅以发布权限登录),我只需要登录一次,这就是我想要的。

不过我确实需要这两种权限。我浏览了 Facebook Android 登录 guide where they claim that you should use the LoginButton since it can store the permissions required and then get all in one login. Is this not possible with the LoginManager? I looked all over the internet and this 是唯一一个说 LoginManager 使用读取 发布登录的地方,但 LoginButton 可以同时执行这两种操作。

这一切都是真的吗?将登录名从 LoginManager 更改为 LoginButton 并不是一项艰巨的工作,但我只是想知道是否有任何方法可以使用 LoginManager 同时使用读取和发布权限登录,这似乎很奇怪,这不是'不可能。

我自己解决了。

我完全误解了 facebook 登录的工作原理,但在阅读 facebook 后 api 我终于解决了它。

如果您需要阅读和发布权限,您需要在不同的位置请求它们。当我第一次登录到应用程序时,我只使用 loginManager 请求读取权限(就像我以前所做的那样)。只有当用户将内容发布到 facebook 时,我才会检查用户是否具有发布权限。如果没有,我启动一个新的 loginManager 并请求它。

由于用户已经登录过一次,只需用户同意发布权限即可,所以没有任何麻烦。