2017-04-20 161 views
0

我做了Facebook登錄,但我不知道如何獲得電子郵件地址,並以另一種形式Android開Facebook的電子郵件地址

所以顯示出來,這是代碼

private void nextActivity(Profile profile){ 
    if(profile != null){ 
     Intent main = new Intent(LogInTo.this, SetUsername.class); 
     main.putExtra("name", profile.getFirstName()); 
     main.putExtra("surname", profile.getLastName()); 
     //main.putExtra("email", profile.get()); 
     main.putExtra("imageUrl", 
     profile.getProfilePictureUri(200,200).toString()); 
     startActivity(main); 
     finish(); 
    } 
} 

這是我的回調

LoginButton loginButton = (LoginButton)findViewById(R.id.loginButton); 
    FacebookCallback<LoginResult> callback = new 
    FacebookCallback<LoginResult>() { 
     @Override 
     public void onSuccess(LoginResult loginResult) { 
      Profile profile = Profile.getCurrentProfile(); 
      nextActivity(profile); 
      Toast.makeText(getApplicationContext(), "Logging in...", Toast.LENGTH_SHORT).show(); 

     } 

     @Override 
     public void onCancel() { 
     } 

     @Override 
     public void onError(FacebookException e) { 
     } 
    }; 
    loginButton.setReadPermissions(Arrays.asList("user_friends")); 
    loginButton.registerCallback(callbackManager, callback); 

而且這是你從Facebook獲得的電子郵件地址顯示在另一種形式的代碼

Bundle inbundle = getIntent().getExtras(); 
    String name = inbundle.get("name").toString(); 
    String surname = inbundle.get("surname").toString(); 

    FbFullname = (EditText) findViewById(R.id.fbfullname); 
    FbFullname.setText("" + name + " " + surname); 

    FbUsername = (EditText) findViewById(R.id.fbusername); 
    FbType = (EditText) findViewById(R.id.fbtype); 
    FbEmail = (EditText) findViewById(R.id.fbemail); 
+0

你沒有問用戶權限讀取他們的電子郵件。 – CBroe

+0

我應該在這裏添加嗎? loginButton.setReadPermissions(Arrays.asList(「user_friends」)); –

+0

Sharmaine Shane Amansec Cinens你已經收到郵件了嗎?我也有這個問題 –

回答

0
loginButton.setReadPermissions("public_profile email");` 

在創建loginButton之後添加此行。

,併爲獲得詳細

GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() { 
     @Override 
     public void onCompleted(JSONObject object, GraphResponse response) { 

      JSONObject json = response.getJSONObject(); 
      try { 
       if (json != null) { 

        JSONObject data = json.getJSONObject("picture").getJSONObject("data"); 
        String name=json.getString("name"); 
        String email= json.getString("email"); 
        String picUrl=data.getString("url"); 
       } 

      } catch (JSONException e) { 

      } 
     } 
    }); 
+0

我已經添加這個,但如何獲得它並以另一種形式顯示它? –

+0

我已更新我的答案。在'onSuccess()'中加入。 –

+0

增加了,但是如何在textview中顯示電子郵件。 –

相關問題