【问题标题】:How to access the Google Calendar Resource API?如何访问 Google 日历资源 API?
【发布时间】:2015-03-01 14:22:38
【问题描述】:

this SO post 中所述,在开发者控制台中启用 Google 日历 API 后,我可以正常访问它。但是,我在要启用的列表中找不到 Google 日历资源 API。尽管如此,我还是尝试通过 OAuth 2.0 访问资源 API,就像我访问日历 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 发布到具有以下标题的以下 URL:

  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

【问题讨论】:

  • 此 API 仅供 Google Apps 管理员以 Google 数据 API 供稿的形式检索和管理其域的 Google 日历资源。您是该域的管理员吗??
  • 是的,我是该域的管理员。
  • 您尝试访问的实际资源 URL 是什么?
  • 我还没有到访问资源的阶段。我目前只是想创建一个资源。我已经用我的示例代码编辑了我的问题。

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


【解决方案1】:

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

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

【讨论】:

  • 您好,感谢分享。我试图在标题中使用你的方法,但它仍然给我同样的错误。您能否分享更多有关您使用的 POST URL 和内容的详细信息?谢谢! 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 }
  • 我无法找到安全性>API 参考,因为您的链接表明我应该能够找到。但是,我确实从 console.developers.google.com 启用了 Admin SDK
  • 我刚刚获得了超级管理员访问权限,现在我可以看到 Security>API Reference。是的,API 访问已经启用。我希望有关于这个 API 的更好的文档。非常感谢您的帮助。
  • 顺便问一下,您是超级管理员吗?我试图弄清楚让这个 API 工作需要什么。谢谢!
猜你喜欢
  • 1970-01-01
  • 2016-09-13
  • 2014-11-19
  • 1970-01-01
  • 2013-10-24
  • 2016-03-25
  • 2016-12-17
  • 2015-02-14
  • 2014-01-20
相关资源
最近更新 更多