1

我需要用户电子邮件地址,我想在 facebook sdk 中设置电子邮件权限。

你能给我一些想法吗?

我的代码:

 @Deprecated
    public void authorize(Activity activity, String[] permissions, final DialogListener listener) {
        permissions =new String[] {"offline_access","video_upload","publish_stream","user_photos","email","read_friendlists"};      
        authorize(activity, permissions, DEFAULT_AUTH_ACTIVITY_CODE, SessionLoginBehavior.SSO_WITH_FALLBACK, listener);
    }

我是这样做的。这是行不通的。

4

3 回答 3

3

试试这个:

you set the permission like 
String[] Permissions = {"email", "offline_access"};
于 2013-02-06T13:35:23.187 回答
1

更改您的授权代码,如下所示:

 public void authorize(Activity activity, String[] permissions,
        int activityCode, final DialogListener listener) {

    boolean singleSignOnStarted = false;

    mAuthDialogListener = listener;

    // Prefer single sign-on, where available.
    if (activityCode >= 0) {
        singleSignOnStarted = startSingleSignOn(activity, mAppId,
                permissions, activityCode);
    }
    // Otherwise fall back to traditional dialog.
    if (!singleSignOnStarted) {
        startDialogAuth(activity, permissions);
    }
}
于 2013-02-06T13:57:26.357 回答
0

我已经检查了这个问题,这很简单。这是您想要的代码:

Session currentSession = Session.getActiveSession();
    if (currentSession == null || currentSession.getState().isClosed()) {
        Session session = new Session.Builder(context).build();
        Session.setActiveSession(session);
        currentSession = session;
    }

    if (currentSession.isOpened()) {
        // Do whatever u want. User has logged in

    } else if (!currentSession.isOpened()) {
        // Ask for username and password
        OpenRequest op = new Session.OpenRequest((Activity) context);

        op.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
        op.setCallback(null);

        List<String> permissions = new ArrayList<String>();
        permissions.add("publish_stream");
        permissions.add("user_likes");
        permissions.add("email");
        permissions.add("user_birthday");
        op.setPermissions(permissions);

        Session session = new Builder(MainActivity.this).build();
        Session.setActiveSession(session);
        session.openForPublish(op);
    }

现在,onActivityResult看看会话是否打开并在那里做你的工作,比如获取 userID、access_token 等等。

希望这会对您有所帮助。

于 2013-05-03T10:43:34.957 回答