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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:59:03+00:00 2026-06-18T23:59:03+00:00

I want to list calendar events using new Calendar API v3 . I have

  • 0

I want to list calendar events using new Calendar API v3. I have read that article (Calendar API v3, 2-legged OAuth & Java) and I did authentication in same way. Please see my factory:

import java.io.IOException;

import com.gene.herder.google.GoogleApiSettings;
import com.google.api.client.auth.oauth.OAuthHmacSigner;
import com.google.api.client.auth.oauth.OAuthParameters;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.Calendar.Builder;
import com.google.api.services.calendar.CalendarRequest;
import com.google.api.services.calendar.CalendarRequestInitializer;

public final class CalendarApiFactory {

    private GoogleApiSettings settings;

    public CalendarApi createCalendarApi() {
        Calendar calendar = createBuilder(settings).build();

        CalendarApi calendarApi = new CalendarApi();
        calendarApi.setCalendar(calendar);
        return calendarApi;
    }

    private Builder createBuilder(GoogleApiSettings settings) {
        HttpTransport transport = new NetHttpTransport();
        JacksonFactory jsonFactory = new JacksonFactory();

        OAuthParameters oauthParameters = createOAuthParameters(settings);

        Builder builder = new Builder(transport, jsonFactory, oauthParameters);
        builder.setApplicationName("MY-COMPANY-MY-APP/1.0");
        builder.setCalendarRequestInitializer(new SettingsCalendarRequestInitializer(settings));
        return builder;
    }

    private OAuthParameters createOAuthParameters(GoogleApiSettings settings) {
        OAuthParameters oauthParameters = new OAuthParameters();
        oauthParameters.version = "1";
        oauthParameters.consumerKey = settings.getClientKey();
        oauthParameters.signer = createSigner(settings);
        return oauthParameters;
    }

    private OAuthHmacSigner createSigner(GoogleApiSettings settings) {
        OAuthHmacSigner signer = new OAuthHmacSigner();
        signer.clientSharedSecret = settings.getClientSecret();
        return signer;
    }

    public void setSettings(GoogleApiSettings settings) {
        this.settings = settings;
    }
}

class SettingsCalendarRequestInitializer extends CalendarRequestInitializer {

    private GoogleApiSettings settings;

    public SettingsCalendarRequestInitializer(GoogleApiSettings settings) {
        this.settings = settings;
    }

    @Override
    protected void initializeCalendarRequest(CalendarRequest<?> request) throws IOException {
        request.setKey(settings.getApiKey());
    }
}

After that I implemented CalendarApi in this way:

import java.io.IOException;

import com.google.api.client.util.ArrayMap;
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.Calendar.Events.Insert;
import com.google.api.services.calendar.Calendar.Events.List;
import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.Events;

public class CalendarApi {

    private Calendar calendar;

    public Events listEvents(String calendarId) throws IOException {
        // Add the xoauth_requestor_id query parameter to let the API know
        // on behalf of which user the request is being made.
        ArrayMap<String, Object> customKeys = new ArrayMap<String, Object>();
        customKeys.add("xoauth_requestor_id", calendarId);

        List events = calendar.events().list("primary");
        events.setUnknownKeys(customKeys);
        return events.execute();
    }

    public void setCalendar(Calendar calendar) {
        this.calendar = calendar;
    }
}

My domain configuration looks like this:
Advanced Tools => Manage third party OAuth Client access
enter image description here

and my Console APIs looks like this:

enter image description here

Now if I invoke my listEvents method with “user1@my-company-domain.com” parameter everything works OK. I can see all events from specified calendar.

But in the case when I pass any other domain user I get “Invalid Credentials” exception all the time. Stacktrace:

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"
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:143) ~[google-api-client-1.13.2-beta.jar:1.13.2-beta]
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:115) ~[google-api-client-1.13.2-beta.jar:1.13.2-beta]
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40) ~[google-api-client-1.13.2-beta.jar:1.13.2-beta]
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:309) ~[google-api-client-1.13.2-beta.jar:1.13.2-beta]
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1090) ~[google-http-client-1.13.1-beta.jar:1.13.1-beta]
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:407) ~[google-api-client-1.13.2-beta.jar:1.13.2-beta]
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:340) ~[google-api-client-1.13.2-beta.jar:1.13.2-beta]
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:458) ~[google-api-client-1.13.2-beta.jar:1.13.2-beta]
    at com.gene.herder.google.calendar.CalendarApi.listEvents(CalendarApi.java:31) ~[CalendarApi.class:na]

My maven dependencies looks like this:

<!-- Google API -->
<dependency>
  <groupId>com.google.apis</groupId>
  <artifactId>google-api-services-calendar</artifactId>
  <version>v3-rev22-1.13.2-beta</version>
</dependency>
<dependency>
  <groupId>com.google.http-client</groupId>
  <artifactId>google-http-client-jackson2</artifactId>
  <version>1.13.1-beta</version>
</dependency>
<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client-jetty</artifactId>
  <version>1.13.1-beta</version>
</dependency>

Why it doesn’t work? I thought I can use that API for any user I want. Where I have made mistake?

  • 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-18T23:59:04+00:00Added an answer on June 18, 2026 at 11:59 pm

    We have to enable Two-legged OAuth access control option in CPanel. With this option API works OK.
    You can find this option on:
    Advanced Tools => Manage OAuth domain key => Two-legged OAuth access control

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

Sidebar

Related Questions

I have a list of calendar events I want to upload into mysql. Some
For example, the API: https://developers.google.com/apis-explorer/#p/calendar/v3/calendar.calendarList.list?_h=4& need to use OAuth 2.0 to authorize before making
I am using the google-api-php-client (API v3) to display a list of events from
I have a small widget on my website that contains a list of events.
I want to restrict entry of new item into sharepoint calendar list with the
I want to list all files in a directory Using PyroCMS. Using the Files
I want to list all files on an FTP server using PHP. According to
I want to list messages that received specific user from other users group by
I have a list of work orders that I am dropping into a Full
I want to retrieve latest two events from calendar Event table in Liferay. I

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.