“Login Required” 401 Unauthorized message when calling the v3 Google Calendar API using a Service Account via OAuth 2.0

后端 未结 6 632
时光取名叫无心
时光取名叫无心 2020-12-29 06:35

First, let me explain what I am trying to do, as this is a two part question.

I am building a JAX-RS service that internally authenticates with a Google account via

6条回答
  •  萌比男神i
    2020-12-29 07:19

    I am an Android Mobile App Developer. I am making an application using Google Calendar API (OAuth 2.0). I also faced this same error. But now, I have resolved the error. I am writing the scenario and the solution for it.
    The url of getting the Calendar Event for the particular calendar (Mobile App API):

    https://www.googleapis.com/calendar/v3/calendars/en.indian%23holiday%40group.v.calendar.google.com/events?access_token=ya29.AHES6ZQyP3iDZM8PF-7ZqZE8oKmWAgUX55sPGPTjGbM5A
    

    In this url, we have to add the calendarId. The format of the url is;

    https://www.googleapis.com/calendar/v3/calendars//events
    

    I was not encoding the calendarId before adding to the url. I encoded the calendarId and then made the Http request. All went fine then.

    final String accessToken=dataStore.getAccessToken();
    
        List params = new LinkedList();
        params.add(new BasicNameValuePair("access_token", accessToken));
        String paramString = URLEncodedUtils.format(params, "utf-8");
    
        final String url = String.format(AuthConstants.CALENDAR_EVENTS_URI,URLEncoder.encode(calendarId))+"?"+ paramString;
    

    Now the calendar events are returned in the JSON.

提交回复
热议问题