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 6536737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:31:48+00:00 2026-05-25T10:31:48+00:00

I am trying to get a user’s access token using twitter4j in my appengine

  • 0

I am trying to get a user’s access token using twitter4j in my appengine project. My code is below

    HttpSession session = req.getSession();
    String tokenCopy = (String) session
            .getAttribute(Constants.TOKEN_SESSION_KEY);
    String tokenSecretCopy = (String) session
            .getAttribute(Constants.TOKENSECRET_SESSION_KEY);

    String oauth_token = req.getParameter("oauth_token");
    //The above is the same as the tokenCopy, verified by printing.
    String oauth_verifier = req.getParameter("oauth_verifier");

    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(Constants.CONSUMER_KEY,
            Constants.CONSUMER_SECRET);

    String extraHTML = "NOTHING\n";

    try {
        AccessToken accessToken;
        accessToken = twitter
                .getOAuthAccessToken(tokenCopy, oauth_verifier);
        // accessToken = twitter.getOAuthAccessToken(oauth_verifier);
        // accessToken = twitter.getOAuthAccessToken();

        String accessTokenStr = accessToken.getToken();
        String accessTokenSecret = accessToken.getTokenSecret();
        extraHTML = "<p>accessToken = " + accessTokenStr
                + ", accessTokenSecret = " + accessTokenSecret + "</p>\n";

        // TODO latertwitter.setOAuthAccessToken(accessToken);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        extraHTML = "<pre>" + e.getMessage() + "</pre>\n";
    }

Sadly, when my code runs, I always get the exception

401:Authentication credentials (https://dev.twitter.com/docs/auth) were missing or
incorrect. Ensure that you have set valid conumer key/secret, access token/secret,
and the system clock in in sync.

I know my CONSUMER_KEY and CONSUMER_SECRET are correct (I used them to create the twitter auth url and that works well). What am I missing here? Should I be passing something else to the call to getOAuthAccessToken() ?

Thanks.

  • 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-25T10:31:48+00:00Added an answer on May 25, 2026 at 10:31 am

    I’m using RequestToken object, instead of String, everything else looks same.

    I mean that when i’m preparing authentication url, i’m doing following:

    RequestToken requestToken = twitter.getOAuthRequestToken(callbackUrl);
    session.setAttribute(Constants.TOKEN_SESSION_KEY, requestToken);
    

    and instead of your code’s line #2 it will be:

    RequestToken tokenCopy = (RequestToken) session.getAttribute(Constants.TOKEN_SESSION_KEY);
    

    Everything else looks correct.

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

Sidebar

Related Questions

I'm trying to get the following code working: string url = String.Format(@SOMEURL); string user
I am trying to find a way to get the source code for (user
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I'm trying to get user GUID from Active Directory. My code: DirectoryEntry entry =
I'm trying to get the user's login details from the database using $SETTINGS[admin_username] and
I'm trying to get the user to login using their Facebook account on the
I'm trying to get the current user info in my plugin using the func
I am trying to get a notification when an user comments using the social
I am trying to get FB user's full name using the access_token. I have
I am trying to get a user back in SharePoint Client OM using EnsureUser.

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.