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

  • SEARCH
  • Home
  • 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 6114089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:56:02+00:00 2026-05-23T14:56:02+00:00

How can I get the accessToken from the anonymous inner class below? when I

  • 0

How can I get the accessToken from the anonymous inner class below? when I try to use the accessToken outside the class it shows up as null. I tried to display a toast with the accessToken right after I closed the inner class and it just shows up as null. I want to be able to use the accessToken in an asynctask to fetch some data. How can I go about doing this?

public class main extends Activity {

        public static final String CALLBACK_URL = "url";
        public static final String CLIENT_ID = "id";

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                String url =
                    "https://foursquare.com/oauth2/authenticate" + 
                        "?client_id=" + CLIENT_ID + 
                        "&response_type=token" + 
                        "&redirect_uri=" + CALLBACK_URL;

                // If authentication works, we'll get redirected to a url with a pattern like:  
                //
                //    http://YOUR_REGISTERED_REDIRECT_URI/#access_token=ACCESS_TOKEN
                //
                // We can override onPageStarted() in the web client and grab the token out.
                WebView webview = (WebView)findViewById(R.id.webView);
                webview.getSettings().setJavaScriptEnabled(true);
                webview.setWebViewClient( new WebViewClient() {
                    public void onPageStarted(WebView view, String url, Bitmap favicon) {
                        String fragment = "#access_token=";
                        int start = url.indexOf(fragment);
                        if (start > -1) {

                            // You can use the accessToken for api calls now.
                            String accessToken = url.substring(start + fragment.length(), url.length());
                            Toast.makeText(main.this, "Token: " + accessToken, Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                webview.loadUrl(url);

            }
        }
  • 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-23T14:56:03+00:00Added an answer on May 23, 2026 at 2:56 pm
         String accessToken = 
             url.substring(start + fragment.length(), url.length());
    

    There is your access token.

    You can pass it to somewhere else in your program. You need to modify the inner class given in the example to fit your needs. As of now, it just displays the token in a dialog box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can get all triples with value null in specific field? All people with date_of_birth
I can get easily see what projects and dlls a single project references from
I can get the executable location from the process, how do I get the
I can get a list of running threads from Process.GetCurrentProcess().Threads, but I need to
How can i get access token for searching venues in foursquare. From this gem,
Reading on this oauth tutorial . The code below, shows how this can be
How can I get the access token from a foursquare request in cocoa? I
I can get both System.Net.Mail and System.Web.Mail to work with GMail, but I can't
Logging can get complicated, quickly. Considering that you have some code, how do you
I can get simple examples to work fine as long as there's no master

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.