本文介绍了android facebook sdk - 为 openActiveSession 设置权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Facebook SDK 集成到 Android 应用程序中.我从 Facebook 手册中得到了代码.它使用 Session.openActiveSession 然后请求图形用户.如何在不使用 LoginButton 类的情况下请求更多权限?

I am trying to integrate Facebook SDK to an android app. I got the code from Facebook manual. It uses Session.openActiveSession and then request a graph user. How could I request for more permissions without using LoginButton class?

Session.openActiveSession(this, true, new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);

        if (session.isOpened()) {
            Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {
                        // got user graph
                    } else {
                        // could not get user graph
                    }
                }
            });
        }
    }
});

谢谢.

推荐答案

试试这个:

mCallback = new Session.StatusCallback() {...}; // the code you already have

Session.OpenRequest request = new Session.OpenRequest(mContext);
request.setPermissions(Arrays.asList("email", "user_birthday"));
request.setCallback(mCallback );

// get active session
Session mFacebookSession = Session.getActiveSession();
if (mFacebookSession == null || mFacebookSession.isClosed())
{
    mFacebookSession = new Session(mContext);
    Session.setActiveSession(mFacebookSession);
}
mFacebookSession.openForRead(request);

这篇关于android facebook sdk - 为 openActiveSession 设置权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 21:42