如何访问Google Calendar Resource API?

时间:2015-01-03 14:37:37

标签: meteor google-api google-calendar-api google-oauth google-admin-sdk

按照this SO post中的说明,我可以在开发人员控制台中启用Google Calendar API后轻松访问它。但是,我无法在列表中找到Google Calendar Resource API来启用。尽管如此,我还是尝试通过OAuth 2.0访问资源API,就像我访问Calendar API一样,但是我收到以下错误:

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> 

我如何让它发挥作用?如果你已经开始工作了,请分享!

编辑:为了提供更多细节,我使用Meteor JS通过以下标题发布到以下网址:

  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 个答案:

答案 0 :(得分:0)

我可以通过在请求中添加以下内容来使其工作:

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