How to retrieve Twitter and facebook Authentication and Token through Android's Account Manager classes

后端 未结 3 1537
滥情空心
滥情空心 2021-02-03 10:36

I want to retrieve token via Account Manager classes. Here is sample code that works for twitter but not for facebook plz help me.

public class AccountMana         


        
相关标签:
3条回答
  • 2021-02-03 11:14

    Just for information, the facebook application part of getAuthToken is not implemented. When you decompile it, you see that it just returns null.

    You should use the Facebook SDK.

    0 讨论(0)
  • 2021-02-03 11:15

    Call AccountManager.getAccountsByType(null) to retrieve all accounts, and check the returned account data includes the information you need. It may simply not be exposed.

    Try calling AccountManager.blockingGetAuthToken instead. Also, make sure your manifest has the USE_CREDENTIALS permission set correctly.

    You can see this discussion How to retrieve an Facebook-AuthToken from the accounts saved on Android

    But I would also suggest Facebook SDK with offline access permission(This permission makes the access token returned by the OAuth endpoint long-lived, otherwise auth token is valid only for 1 hour.)

    0 讨论(0)
  • 2021-02-03 11:36

    You can also create intent and obtain token from facebook application

    Intent intent = new Intent();
    intent.setClassName("com.facebook.katana", "com.facebook.katana.ProxyAuth");
    intent.putExtra("client_id", apiKey);
    intent.putExtra("scope", scope);
    
    try {
        activity.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException e) {
        return false;
    }
    

    Then onActivityResult(int requestCode, int resultCode, Intent data) of you activity you can get the token using

    data.getStringExtra("access_token");
    
    0 讨论(0)
提交回复
热议问题