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
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.
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.)
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");