如何访问Google日历资源API? [英] How to access the Google Calendar Resource API?

查看:126
本文介绍了如何访问Google日历资源API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发者控制台中启用Google Calendar API后,我可以很好地访问Google Calendar API,如这个SO贴子。但是,我无法在列表中找到要启用的Google日历资源API。尽管如此,我仍尝试通过 OAuth 2.0 就像我如何访问Calendar API,但出现以下错误:

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!

编辑:为了提供更多细节,我使用流星JS发布到下面的URL,标题如下:

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


推荐答案

我可以通过将下列内容添加到请求中来工作:

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

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

这篇关于如何访问Google日历资源API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆