0

我的代码可以很好地获取基本的用户信息。但现在我需要用户的电子邮件。我需要在打开的会话上设置权限“电子邮件”。但我不知道在哪里......在打开时,ito 不起作用。这是活动的完整代码

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();


  }

我必须在哪里设置阅读电子邮件的新权限?谢谢和对不起我的英语

4

2 回答 2

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":[{"employer":{"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","education":[{"type":"unknown","school":{"id":"some_id","name":"school_name"}}],"updated_time":"2013 -07-31T09:01:15+0000","id":"some_id","first_name":"some_name","timezone":3.5,"username":"user_name","email":"myemailid@email.com","verified":true,"name":"name_in_full","last_name":"some_name","gender":"some_gender"}},错误:null,isFromCache:false}

我已经编辑了响应中的值。

于 2013-08-01T11:17:43.433 回答
0

您可以设置权限:请参阅此Graph api 不返回用户电子邮件 ID设置从 Facebook 登录获取用户电子邮件 ID 的权限

享受编码:)

于 2013-10-22T07:42:41.020 回答