2017-10-27 16 views
0

Facebookのユーザーのメールアドレス、ユーザー名、姓を取得したいと考えています。私は名前と姓を検索しました。しかし、私は電子メールを取得する方法を知らない。Facebookのユーザーメールを取得する方法

私はこのコードを持っている:

fbloginButton.registerCallback(callbackManager, new 
FacebookCallback<LoginResult>() 
    { 
     @Override 
     public void onSuccess(LoginResult loginResult) 
     { 
      Intent intent = new 
      Intent(LoginTienda.this,Comprador_registrado.class); 
      startActivity(intent); 
     } 

     @Override 
     public void onCancel() 
     { 

     } 

     @Override 
     public void onError(FacebookException error) 
     { 
      String msgerror = error.getMessage(); 
      Toast.makeText(LoginTienda.this, msgerror, 
      Toast.LENGTH_SHORT).show(); 
     } 
    }); 

    profileTracker = new ProfileTracker() 
    { 
     @Override 
     protected void onCurrentProfileChanged(Profile oldProfile, Profile 
     currentProfile) 
     { 

      if(currentProfile == null) 
      { 

       Intent i = new 
       Intent(LoginTienda.this,MainActivity.class); 
       startActivity(i); 
      } 
      else 
      { 
       //get the username and last name 
       nombrefb = currentProfile.getFirstName(); 
       apellidofb = currentProfile.getLastName(); 

       Toast.makeText(getApplicationContext(), 
       apellidofb,Toast.LENGTH_LONG).show(); 
      } 
     } 
    }; 

は、どのように私は、ユーザーのメールを取得することができますか?プロファイルクラスでgetEmailとしてメソッドを見つけることができません。名前と姓を取得するためにgetName()、getFirstName()またはgetLastName()が見つかりました。

ありがとうございました。

また、私はこのコードを持っている:

public void onSuccess(LoginResult loginResult) 
     { 
       GraphRequest graphRequest = GraphRequest.newMeRequest(
        loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() 
        { 
         @Override 
         public void onCompleted(JSONObject object, GraphResponse response) 
         { 
          String rsp = response.toString(); 
          Toast.makeText(getApplicationContext(),rsp,Toast.LENGTH_LONG).show(); 
          try 
          { 
           correofb = object.getString("email").toString(); 
          } 
          catch (JSONException e) 
          { 
           e.printStackTrace(); 
          } 
         } 
        }); 

      Bundle parametros = new Bundle(); 
      parametros.putString("campos","email"); 
      graphRequest.setParameters(parametros); 
      graphRequest.executeAsync(); 
     } 

そして私はIDと名前が、無電子メールで観るものを、それを実行した後に。どうしましたか?

+0

https://stackoverflow.com/questions/29295987/android-facebook-4-0-sdk-how-to-get-email-date-of-出産・ジェンダー・オブ・ユーザー – keshav

+0

バンドルのパラメータを変更しよう "campos" with "fields" – Munir

答えて

0

registerCallbackするonSuccessからの方法以下のコール

private void makeGraphRequest(LoginResult loginResult) { 
    GraphRequest request = GraphRequest.newMeRequest(
      loginResult.getAccessToken(), 
      new GraphRequest.GraphJSONObjectCallback() { 
       @Override 
       public void onCompleted(
         JSONObject object, 
         GraphResponse response) { 

        Log.d("response: ", response + ""); 
        try { 

         String id =object.getString("id").toString(); 
         String email = object.getString("email").toString(); 
         String name = object.getString("name").toString(); 
         //String imageurl = "https://graph.facebook.com/" + id + "/picture?type=large"; 
         //object.get("gender"); 
        } catch (Exception e) { 
         e.printStackTrace(); 

        } 

       } 

      }); 

    Bundle parameters = new Bundle(); 
    parameters.putString("fields", "id,name,email,gender, birthday"); 
    request.setParameters(parameters); 
    request.executeAsync(); 
} 
+0

お返事ありがとうございます。私は、上記のポストで問題の説明についてさらに詳しく述べました。私は何が間違っているのか分からない。 – axmug

+0

コードを表示してバンドルパラメータのキー "フィールド"を "campos"に変更する理由を教えてください。そのフィールドを "フィールド"で変更するだけです。 – Munir

関連する問題