我的代码可以很好地获取基本的用户信息。但现在我需要用户的电子邮件。 我需要在打开的会话中设置permision“email”。但我不知道在哪里...... 在公开场合,它不起作用。 这是活动的完整代码
public class MainActivityFB extends Activity {
TextView v;
String FbToken;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.black);
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.actionbar));
final List<String> PERMS = new ArrayList<String>(); //= new String[] { "read_stream", "email" }; //set email permision.
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
PERMS.add("read_stream");
PERMS.add("email");
NewPermissionsRequest aa = new NewPermissionsRequest(MainActivityFB.this, PERMS);
System.out.println("Chiamo la richiesta di permessi " + aa.toString());
session.requestNewReadPermissions(aa); //this do nothings. no permision was called
if (session.isOpened()) {
System.out.println("session token " + session.getAccessToken());
FbToken = session.getAccessToken();
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
String nickname = user.getName();
String id = user.getId();
//user.getEmail()... not found
//Do somethings, start the new activity...
finish();
}
}
});
} else {
//Session not open
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
Session session = Session.getActiveSession();
}
我必须设置新的权限来阅读电子邮件吗? 谢谢,抱歉我的英文
答案 0 :(得分:0)
以下是您在 onCompleted回调方法中从Response对象获得的完整响应。 检查响应是否为空(为安全起见),然后您可以解析JSON响应并从中获取电子邮件ID。
权限“电子邮件”在此处有效:
PERMS.add( “read_stream”); PERMS.add( “电子邮件”); // - 有效权限
在日志中打印如下: Log.i(“fb_response”,response.toString());
{响应:responseCode:200,graphObject:GraphObject {graphObjectClass = GraphObject,state = {“work”:[{“雇主”:{“id”:“some_number”,“name”:“some_name” }“],”location“:{”id“:”some_id“,”name“:”ab,cd“},”middle_name“:”name“,”locale“:”en_US“,”link“:”https ://www.facebook.com/link_to_your_profile”, “教育”:[{ “类型”: “未知”, “学校”:{ “ID”: “SOME_ID”, “名”: “school_name”}}], “updated_time”: “2013-07-31T09:01:15 + 0000”, “ID”: “SOME_ID”, “FIRST_NAME”: “some_name”, “时区”:3.5, “用户名”: “USER_NAME”,“电子邮件“:”myemailid@email.com“,”已验证“:true,”name“:”name_in_full“,”last_name“:”some_name“,”gender“:”some_gender“}},错误:null,isFromCache:false} 强>
我已在响应中编辑了值。
答案 1 :(得分:0)