【问题标题】:Add Google API to meteor project将 Google API 添加到流星项目
【发布时间】:2012-10-18 21:36:41
【问题描述】:

我正在尝试将 Google API 链接到我的流星项目,但似乎无法加载。 文档说要添加

script src="https://apis.google.com/js/client.js?onload=OnLoadCallback"></script>

到标题,我们不能直接在流星中做。

我尝试获取脚本的本地副本并将其添加到客户端文件夹,但在加载时仍然得到“未定义 gapi”。这种方法适用于 filepicker.io,但不适用于这个。

知道在哪里或如何加载库吗?

【问题讨论】:

标签: google-api meteor


【解决方案1】:

您可以使用 Meteor 的内置外部服务进行身份验证,他们为 google 提供了一个特定的服务: http://docs.meteor.com/#meteor_loginwithexternalservice

要加载客户端 API,只需将其包含在应用程序主 html 文件的 &lt;head&gt; 部分。

<script src="https://apis.google.com/js/client.js?onload=OnLoadCallback"></script>

您可以通过在控制台中运行gapi 来确认它已正确加载

【讨论】:

  • 并非如此。这是登录服务的一个很好的选择,但谷歌公开了一个完整的 API 来以编程方式从不同的平台(如 ruby​​、python、js 等)操作日历、任务、地图和大多数其他服务。我正在尝试在我的项目中导入该库所以我可以将事件和任务添加到 gCalendar 和 gtasks
  • 当您尝试在 mainapplicationfile.html 文件中加载它时会发生什么?
  • 好吧,当在meteor.startup控制台上使用"gapi.client.load("calendar","v3")时返回一个'Cannot load method 'load' of Undefined。页面加载后我可以从控制台调用“gapi”并从控制台正确发出相同的命令。看起来该对象在meteor.startup 或其他东西中不可用。尝试从template.rendered 调用该函数但也没有工作。
【解决方案2】:

发现:最好的方法是使用 Google RESTful api。你可以在This SO Question看到一个工作示例

【讨论】:

    【解决方案3】:
    // Create the script tag, set the appropriate attributes
    var script = document.createElement('script');
    script.src = 'https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap';
    script.async = true;
    
    // Attach your callback function to the `window` object
    window.initMap = function() {
      // JS API is loaded and available
    };
    
    // Append the 'script' element to 'head'
    document.head.appendChild(script);
    

    reference

    【讨论】:

      猜你喜欢
      • 2017-04-18
      • 2013-01-27
      • 1970-01-01
      • 2016-01-29
      • 1970-01-01
      • 2013-02-21
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多