无法添加 publish_stream 权限

Posted

技术标签:

【中文标题】无法添加 publish_stream 权限【英文标题】:Can not add a publish_stream permission 【发布时间】:2013-10-26 13:43:21 【问题描述】:

您好,我尝试在我的应用中添加 public_stream 权限。我在控制台中打印了我的会话信息,我发现当我添加公共权限时,我的会话状态为 CLOSED_LOGIN_FAILED,当我删除此权限时,会话状态为 OPENING,并且我设置了其他读取权限。

这是我的代码:

@Override
public void onCreate(Bundle savedInstanceState) 
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) 

    View view = inflater.inflate(R.layout.facebook_login_view, container,
            false);

    facebookButton = (LoginButton) view.findViewById(R.id.facebookAuth);
    facebookButton.setFragment(LoginAuthFragment.this);
    //facebookButton.setReadPermissions("email", "user_birthday");
    facebookButton.setPublishPermissions("publish_stream", "email", "user_birthday");

    return view;

private Session.StatusCallback callback = new Session.StatusCallback() 
    @Override
    public void call(Session session, SessionState state, Exception exception) 
            onSessionStateChange(session, state, exception);
    
;

private void onSessionStateChange(Session session, SessionState state, Exception exception) 
   System.out.println(session);
   System.out.println("Access token: "+session.getAccessToken());

 final User u = new User();

        if(session.isOpened())
            System.out.println("OK");
            final String subscribe;
            if(receiveMail.isChecked())
                subscribe = "1";
            else
                subscribe = "0";
            

            final String access_token=session.getAccessToken();

            Request request = Request.newMeRequest(session, new Request.GraphUserCallback() 

                @Override
                public void onCompleted(GraphUser user, Response response) 
                            if (user != null) 

                                String firstName = user.getFirstName();
                                String lastName = user.getLastName();
                                String userName = "fb_user_"+user.getId();
                                String facebook_id = user.getId();
                                String birthday = user.getBirthday();
                                String email = user.asMap().get("email")
                                        .toString();
                                String response1 = u.checkFacebookUser(
                                        userName, facebook_id, access_token,
                                        birthday, email, subscribe, firstName, lastName);

                                if (response1.equals("GREEN")) 
                                    prefs.setTokenData(u.getToken(),
                                            u.getCreatedAt(), u.getExpires());
                                    Intent loggedIn = new Intent(getActivity().getApplicationContext(),
                                            MainActivity.class);
                                    startActivity(loggedIn);
                                    getActivity().finish();
                                 else if (response1.equals("RED")) 
                                    Toast.makeText(
                                            getActivity()
                                                    .getApplicationContext(),
                                            "Unknown error", Toast.LENGTH_LONG)
                                            .show();
                                 

                            

                
            );
            Request.executeBatchAsync(request);
        


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) 
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);


@Override
public void onSaveInstanceState(Bundle outState) 
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);


@Override
public void onResume() 
    super.onResume();
    Session session = Session.getActiveSession();

    if (session != null &&
            (session.isOpened() || session.isClosed()) ) 
        onSessionStateChange(session, session.getState(), null);
    

    uiHelper.onResume();


@Override
public void onPause() 
    super.onPause();
    uiHelper.onPause();


@Override
public void onDestroy() 
    super.onDestroy();
    uiHelper.onDestroy();

这是我添加 publish_stream 权限时的会话

会话状态:CLOSED_LOGIN_FAILED,令牌:AccessToken 令牌:ACCESS_TOKEN_REMOVED 权限:[],appId:593058290740634

这是我没有获得 publish_stream 权限的会话:

Session state:OPENED, token:AccessToken token:ACCESS_TOKEN_REMOVED permissions:[email, user_birthday, user_friends, basic_info], appId:593058290740634

【问题讨论】:

【参考方案1】:

您必须先获得“basic_info”(这是一种读取权限)才能请求发布权限。

正确的做法是首先向用户请求 email 和 user_birthday 权限,当您准备好发布时(通常在一些用户交互之后),然后请求 publish_stream 权限。

【讨论】:

以上是关于无法添加 publish_stream 权限的主要内容,如果未能解决你的问题,请参考以下文章

facebook api:请求publish_stream是不是需要用户每次登录时的确认

为啥 publish_stream 未在扩展权限参考中列出?

Facebook IOS SDK:检测用户何时拒绝 publish_stream 权限

如何在范围变量中删除权限offline_access和publish_stream

在 facebook 应用程序 MVC 上添加附加权限

授权应用程序时不再识别 Facebook 连接 publish_stream (iOS)