How to access the Google Calendar Resource API?

耗尽温柔 提交于 2019-12-08 07:27:33

问题


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

回答1:


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

headers: {
   Authorization: 'OAuth2 oauth_token=' + accessToken;
}


来源:https://stackoverflow.com/questions/27755951/how-to-access-the-google-calendar-resource-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!