2016-08-18 6 views
1

Facebookのログイン後にユーザー情報を取得しようとしています。ログイン後のAndroidのfacebook

callbackManager = CallbackManager.Factory.create(); 
    loginButton = (LoginButton) findViewById(R.id.login_button); 
    loginButton.setReadPermissions("user_birthday", "email"); 
    final Context contextM = this.getApplicationContext(); 


    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { 
     @Override 
     public void onSuccess(LoginResult loginResult) { 
      String firstName = Profile.getCurrentProfile().getFirstName(); 
      String lastName = Profile.getCurrentProfile().getLastName(); 
      String url = Profile.getCurrentProfile().getProfilePictureUri(100, 100).toString(); 

      final ImageView mImageView = (ImageView) findViewById(R.id.imageView); 
      ImageRequest request = new ImageRequest(url, 
        new Response.Listener<Bitmap>() { 
         @Override 
         public void onResponse(Bitmap bitmap) { 
          mImageView.setImageBitmap(bitmap); 
         } 
        }, 0, 0, null, 
        new Response.ErrorListener() { 
         public void onErrorResponse(VolleyError error) { 
         } 
        }); 
      MySingleton.getInstance(contextM).addToRequestQueue(request); 
     } 

、これは私が取得エラーです:

のjava.lang.NullPointerException:仮想メソッド を起動しようと 'はjava.lang.String型com.facebook.Profile.getFirstName()' にa null オブジェクトリファレンス

答えて

0

グラフリクエストを使用して、次のように結果にアクセスしました。これがあなたに役立つかどうかを確認してください。

+0

@Yura Abramovはあなたの問題を解決しましたか? – Nikhil

+0

はいありがとう! –

0

public_profileの権限が不足していると思われます。これは、first_nameとlastnameの両方を取得することができます。

getRecentlyGrantedPermissions()を使用して、許可されているすべての権限を確認してください。

+0

基本認証だけでfirst_nameとlast_nameを取得するための追加のアクセス権は必要ありません。間違いなくpublic_profile。 apiエクスプローラで試してみてください:/ me?fields = first_name、last_name – luschn

関連する問題