Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7663405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:03:24+00:00 2026-05-31T14:03:24+00:00

I want to retrieve token via Account Manager classes. Here is sample code that

  • 0

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 AccountManagerActivity extends Activity {

    AccountManager mAccountManager;
    AccountManagerFuture<Bundle> c;
    String token;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mAccountManager = AccountManager.get(this);
        Account[] acc = mAccountManager.getAccounts();
        for (int i = 1; i < acc.length; i++) {
            System.out.println("Account name==" + acc[i].name);
            System.out.println("Account Type==" + acc[i].type);
        }
        AuthenticatorDescription[] ad = mAccountManager.getAuthenticatorTypes();
        for (int i = 1; i < ad.length; i++) {
            System.out.println("AuthenticatorDescription==" + ad[i].type);
        }


        tokenForTwitter();
        tokenForFacebook();
    }

    private void tokenForFacebook() {
        Account[] accts = mAccountManager
                .getAccountsByType("com.facebook.auth.login");
        int i = 0;
        if (accts.length > 0) {
            System.out.println("here");
            Account acct = accts[0];
            c = mAccountManager.getAuthToken(acct,
                    "com.facebook.auth.token" , null,
                    this, new AccountManagerCallback<Bundle>() {

                        @Override
                        public void run(AccountManagerFuture<Bundle> arg0) {
                            try {
                                Bundle b = arg0.getResult();
                                System.out.println("Facebook THIS AUHTOKEN: "
                                        + b.getString(AccountManager.KEY_AUTHTOKEN));
                                Intent launch = (Intent) b
                                        .get(AccountManager.KEY_INTENT);
                                if (launch != null) {
                                    startActivityForResult(launch, 0);
                                    return;
                                }
                            } catch (Exception e) {
                                System.out.println("EXCEPTION@AUTHTOKEN");
                            }
                        }
                    }, null);

            c = mAccountManager.getAuthToken(acct,
                    "com.facebook.auth.token.secret" /*
                                                             * what goes here
                                                             */, null, this,
                    new AccountManagerCallback<Bundle>() {

                        @Override
                        public void run(AccountManagerFuture<Bundle> arg0) {
                            try {
                                Bundle b = arg0.getResult();
                                System.out.println("Facebook THIS AUHTOKEN: "
                                        + b.getString(AccountManager.KEY_AUTHTOKEN));
                                Intent launch = (Intent) b
                                        .get(AccountManager.KEY_INTENT);
                                if (launch != null) {
                                    startActivityForResult(launch, 0);
                                    return;
                                }
                            } catch (Exception e) {
                                System.out.println("EXCEPTION@AUTHTOKEN");
                            }
                        }
                    }, null);

            // mHandler.sendMessageDelayed(mHandler.obtainMessage(CALL), 0);

            i++;
        }

    }

    public void tokenForTwitter() {
        Account[] accts = mAccountManager
                .getAccountsByType("com.twitter.android.auth.login");
        int i = 0;
        if (accts.length > 0) {
            System.out.println("here");
            Account acct = accts[0];
            c = mAccountManager.getAuthToken(acct,
                    "com.twitter.android.oauth.token" /* what goes here */, null,
                    this, new AccountManagerCallback<Bundle>() {

                        @Override
                        public void run(AccountManagerFuture<Bundle> arg0) {
                            try {
                                Bundle b = arg0.getResult();
                                System.out.println("twitter THIS AUHTOKEN: "
                                        + b.getString(AccountManager.KEY_AUTHTOKEN));
                                Intent launch = (Intent) b
                                        .get(AccountManager.KEY_INTENT);
                                if (launch != null) {
                                    startActivityForResult(launch, 0);
                                    return;
                                }
                            } catch (Exception e) {
                                System.out.println("EXCEPTION@AUTHTOKEN");
                            }
                        }
                    }, null);

            c = mAccountManager.getAuthToken(acct,
                    "com.twitter.android.oauth.token.secret" /*
                                                             * what goes here
                                                             */, null, this,
                    new AccountManagerCallback<Bundle>() {

                        @Override
                        public void run(AccountManagerFuture<Bundle> arg0) {
                            try {
                                Bundle b = arg0.getResult();
                                System.out.println("twitter THIS AUHTOKEN: "
                                        + b.getString(AccountManager.KEY_AUTHTOKEN));
                                Intent launch = (Intent) b
                                        .get(AccountManager.KEY_INTENT);
                                if (launch != null) {
                                    startActivityForResult(launch, 0);
                                    return;
                                }
                            } catch (Exception e) {
                                System.out.println("EXCEPTION@AUTHTOKEN");
                            }
                        }
                    }, null);

            // mHandler.sendMessageDelayed(mHandler.obtainMessage(CALL), 0);

            i++;
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:03:25+00:00Added an answer on May 31, 2026 at 2:03 pm

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to retrieve a list of the files that has been added or
I want to retrieve items from Fortress via its .NET API and load their
I want to retrieve the moth from a date(in textbox),then If that retrieved month
I want to retrieve all objects (not DOM elements) of a given type created
I want to use facebook's graph api to retrieve a page's photos. Here's the
I'll keep it short. I want to obtain the string value from token. But
Before anything, this is not necessarily a question.. But I really want to know
Ok twitter might be great for social media but for a small app that
I want to retrieve a set of records from a database, do a rs.next()
I want to retrieve stack trace from a user dump file programmatically . There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.