将Google API添加到流星项目



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

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

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

我尝试获取脚本的本地副本并将其添加到客户端文件夹中,但加载时仍未定义" GAPI"。这种方法与filepicker.io一起使用,但对此不使用。

有任何想法加载库的地方或如何加载图书馆?

您可以使用auth的流星内置服务,它们为Google具有特定的服务:http://docs.meteor.com/#meteor_loginwithexternalservice

要加载客户端API,只需将其包含在您应用程序主HTML文件的<head>部分中。

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

您可以通过在控制台中运行gapi

来确认它已正确加载。

找到:最好的方法是使用Google Restful API。您可以在这个问题上看到一个工作示例

// 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);

请参阅参考。

最新更新