How to access the Google Calendar Resource API?
Asked Answered
M

1

1

I can access the Google Calendar API just fine after enabling it in the Developer's Console, as explained in this SO post. However, I can't find the Google Calendar Resource API in the list to enable. In spite of this, I have tried to access the Resource API via OAuth 2.0 like how I access the Calendar API, but I get the following error:

Exception in callback of async function: Error: failed [403] 
<HTML> <HEAD> <TITLE>You are not authorized to use this API.</TITLE> </HEAD> 
<BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>You are not authorized to use this API.</H1> 
<H2>Error 403</H2> </BODY> </HTML> 

How do I get it to work? If you've gotten it to work, please share!

EDIT: To give more details, I am using Meteor JS to POST to the following URL with the headers below:

  var xmlContent = "<?xml version='1.0' encoding='utf-8'?>" +
                  "<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>" +
                    "<apps:property name='resourceId' value='"+ resource._id +"'/>" +
                    "<apps:property name='resourceCommonName' value='"+ resource.resourceName +"'/>" +
                    "<apps:property name='resourceDescription' value='"+ resource.resourceDescription +"'/>" +
                    "<apps:property name='resourceType' value='"+ resource.resourceType +"'/>" +
                  "</atom:entry>";

  var url = "https://apps-apis.google.com/a/feeds/calendar/resource/2.0/example.com/";
  var id = HTTP.post(url, {
    'headers' : {
      'Content-Type': 'application/atom+xml',
      'Authorization': 'OAuth2 oauth_token=' + admin.services.google.accessToken,
      'X-JavaScript-User-Agent': "Google APIs Explorer"
    },
    'content': xmlContent
  }
  , 
  function(error, result) {
    if (error) throw error;
  });//end HTTP.post
Mcilroy answered 3/1, 2015 at 14:37 Comment(4)
This API is available only for Google Apps administrators to retrieve and manage the Google Calendar resources of their domains in the form of Google Data API feeds. Are you admin for this domain??Magnitogorsk
Yes, I am an admin on the domain.Mcilroy
What is the actual resource URL you try to access?Cuttlebone
I am not yet at the stage to access a resource. I am currently just trying to create a resource. I have edited my question with my example code.Mcilroy
B
0

I am able to get it to work by adding the following to the request:

headers: {
   Authorization: 'OAuth2 oauth_token=' + accessToken;
}
Binominal answered 8/1, 2015 at 23:30 Comment(4)
Hi, thanks for sharing. I tried to use your method in the headers, but it still gives me the same error. Can you share more details of the POST URL and contents you use? Thanks! var url = "https://apps-apis.google.com/a/feeds/calendar/resource/2.0/test.org/"; var id = HTTP.post(url, { 'headers' : { 'Content-Type': 'application/atom+xml', 'Authorization': 'OAuth2 oauth_token=' + admin.services.google.accessToken, 'X-JavaScript-User-Agent': "Google APIs Explorer" }, 'content': xmlContent }Mcilroy
I am unable to find the Security>API Reference as your link states I should be able to. However, I did enable the Admin SDK from console.developers.google.comMcilroy
I just got superadmin access and now I can see the Security>API Reference. Yes, the API access was already enabled. I wish there was better documentation on this API. Your help is very much appreciated.Mcilroy
By the way, are you a SuperAdmin? I'm trying to figure out what is necessary to get this API working. Thanks!Mcilroy

© 2022 - 2024 — McMap. All rights reserved.