我需要用户的电子邮件地址,我想在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);
}
我是这样做的。这不起作用。
答案 0 :(得分:3)
试试这个:
you set the permission like
String[] Permissions = {"email", "offline_access"};
答案 1 :(得分: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);
}
}
答案 2 :(得分: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等等。
希望这会以某种方式帮助你。