android get friendlist facebook

时间:2016-11-01 14:01:00

标签: android facebook

我已经使用firebase创建了登录系统。现在我想在另一个页面上与使用相同应用程序的用户朋友列表。

private static final String TAG = "FacebookLogin";

ProgressDialog progress;

private FirebaseAuth mAuth;

private FirebaseAuth.AuthStateListener mAuthListener;

private CallbackManager mCallbackManager;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    facebookSDKInitialize();
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_facebook_login);


    //Zorgt ervoor dat het lettertype van Until wordt aangepast
    TextView myTextView = (TextView) findViewById(R.id.UntilLogo);
    Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/Ubuntu-Title.ttf");
    myTextView.setTypeface(typeFace);
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("email", "public_profile", "user_friends");
    getlogindetails(loginButton);

    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                Intent myIntent = new Intent(getBaseContext(), MainActivity.class);
                startActivity(myIntent);
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
        }
    };
    mCallbackManager = CallbackManager.Factory.create();

}

private void getlogindetails(LoginButton loginButton) {
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
            handleFacebookAccessToken(loginResult.getAccessToken());
            GraphRequestAsyncTask graphRequestAsyncTask = new GraphRequest(
                    loginResult.getAccessToken(),
                    // AccessToken.getCurrentAccessToken(),
                    "/100001196725148/friends",
                    null,
                    HttpMethod.GET,
                    new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {
                            Intent intent = new Intent(FacebookLoginActivity.this,FriendsFragment.class);
                            try {
                                JSONArray rawName = response.getJSONObject().getJSONArray("data");
                                intent.putExtra("jsondata", rawName.toString());
                                startActivity(intent);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }
            ).executeAsync();
        }

我不知道我做错了什么。它在应用程序

之前一直崩溃

开始。谁知道如何正确使用Grapghrequest?

P.S。

我如何获得Facebook用户ID?

0 个答案:

没有答案