gpt4 book ai didi

android - Facebook SDK 3.8 : permission publish_actions not returned

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:36 24 4
gpt4 key购买 nike

我正在关注 facebook ( https://developers.facebook.com/docs/android/share ) 的 facebook android 共享教程。该应用程序运行良好,我可以通过单击演示共享按钮使用 facebook 登录。所以这是我的应用程序的过程:

  1. 使用 Facebook 登入
  2. Facebook session 对象得到更新,以下权限保存在 session 对象中:user_likes、user_friends、user_status、basic_info
  3. 现在,我想分享一些东西。因此,用户点击共享按钮并请求一个名为 publish_actions 的附加权限

以下代码执行此请求:

public class MainActivity extends Activity {

private Button shareButton;
private UiLifecycleHelper uiHelper;
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
private static final String PENDING_PUBLISH_KEY = "pendingPublishReauthorization";
private boolean pendingPublishReauthorization = false;

...
private void publishStory() {
Session session = Session.getActiveSession();
if( session != null) {
List<String> permissions = session.getPermissions();
if(!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
//Request the new permission here. The answer is processed in onSessionStateChange() method
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}

...

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
//since the session is already open we enter this if branch
if (state.isOpened()) {
shareButton.setVisibility(View.VISIBLE);
//The result of state.equals(SessionState.OPENED_TOKEN_UPDATED) is false which indicates that the session object has not been updated (as far as I understand the fb api)
Log.e(TAG, "state.equals(SessionState.OPENED_TOKEN_UPDATED) = " + state.equals(SessionState.OPENED_TOKEN_UPDATED));
//Output all the current permission the session has (publish_actions is not included here)
List<String> permissions = session.getPermissions();
Iterator<String> it = permissions.iterator();
Log.e(TAG, "Content of list:");
while(it.hasNext())
Log.e(TAG, "permission = " + it.next());
//Since the OPENED_TOKEN_UPDATED has not been updated nothing further happens here
if (pendingPublishReauthorization && state.equals(SessionState.OPENED_TOKEN_UPDATED)) {
pendingPublishReauthorization = false;
publishStory();
}
} else if (state.isClosed()) {
shareButton.setVisibility(View.INVISIBLE);
}
}

所以,虽然这看起来是正确的,但肯定还有一些错误。未授予 publish_actions 权限,但我不明白为什么。只有现有权限保留 publish_actions

进一步说明:我读过一些问题,说应该出现一个额外的弹出窗口,要求用户授予权限。但是,这不会发生在我的情况下。也许这是问题所在?如果是这样,我需要做什么才能获得弹出窗口?

更新:我还尝试了 github 中的以下要点:https://gist.github.com/vishalpawale/5556996由于完全相同的原因,此示例代码失败。它没有获得任何 publish_action 权限。似乎是 Facebook SDK 中的实际错误?

最佳答案

对于发布权限,您应该在应用程序设置中发送请求并发送以供审核,请参阅 https://developers.facebook.com/docs/apps/review/

关于android - Facebook SDK 3.8 : permission publish_actions not returned,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23157419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com