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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:19:01+00:00 2026-06-08T08:19:01+00:00

Error which i am getting: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized { code : 401, errors :

  • 0

Error which i am getting:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
  "code" : 401,
  "errors" : [ {
    "domain" : "global",
    "location" : "Authorization",
    "locationType" : "header",
    "message" : "Invalid Credentials",
    "reason" : "authError"
  } ],
  "message" : "Invalid Credentials"
}

Below code, i am using:

GoogleCredential credential = new GoogleCredential.Builder()
    .setTransport(this.TRANSPORT).setJsonFactory(this.JSON_FACTORY)
    .setClientSecrets(Constants.CLIENT_ID, Constants.CLIENT_SECRET).build();
credential.setAccessToken(tokenResponse.getAccessToken());
credential.setAccessToken(tokenResponse.getRefreshToken());

Till here, i get Refresh token, Access Token, etc

Oauth2 userInfoService = new Oauth2.Builder(this.TRANSPORT,
        this.JSON_FACTORY, credential.getRequestInitializer())
        .setApplicationName(Constants.APPLICATION_NAME).build();

It fails at below line: (Dont know, Why?)

Userinfo userInfo = userInfoService.userinfo().get().execute();

I searched on web, and i get very less examples of it and rare materials.
Any body has any idea on it?

What am i doing wrong?

  • 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-06-08T08:19:03+00:00Added an answer on June 8, 2026 at 8:19 am

    I’m guessing credential.getRequestInitializer() is null.

    I’ve solved this by setting an custom request initializer to the credential object like this

    GoogleCredential credential = new GoogleCredential.Builder()
    .setTransport(this.TRANSPORT).setJsonFactory(this.JSON_FACTORY)
    .setClientSecrets(Constants.CLIENT_ID, Constants.CLIENT_SECRET).setRequestInitializer((new HttpRequestInitializer(){
                    @Override
                    public void initialize(HttpRequest request)
                            throws IOException {
                        request.getHeaders().put("Authorization", "Bearer " + accessToken);
                    }
                })).build()
    

    Google’s documentation especifies the following:

    **
    For example, a call to the UserInfo API using the access_token query string parameter looks like the following:

    GET https://www.googleapis.com/oauth2/v1/userinfo?access_token={accessToken}
    A call to the same API using the access token in the HTTP header looks like the following:

    GET /oauth2/v1/userinfo HTTP/1.1
    Authorization: Bearer {accessToken}
    Host: googleapis.com**

    Hope this will help you

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

Sidebar

Related Questions

I'm getting a function not defined Javascript error with the following code, which uses
I am trying to create full text index but I am getting error which
I am getting this error when calling a web service method which writes to
I am getting the error below, which makes no sense. * Terminating app due
I am getting the following error, which I don't understand... 06-15 22:06:49.196: W/dalvikvm(17622): threadid=1:
I am getting the following error while running my MVC application, which uses the
Good Day Everyone... I’m getting an unexpected WCF error complaining of Known Types which
I've created a test which extends GWTTestCase but I'm getting this error: mvn integration-test
I get the following error: Exception in thread main java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet; at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399) at
Well am using eclipse to make an android app which accesses google calendar API

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.