Javascript 无法在Meteor-OAuth问题中使用Google日历API?
我正在开发一个使用GoogleCalendarAPI的web应用程序(目前,我只希望能够从日历中检索和显示事件列表),但我还不能正确地调用API。从技术上讲,它是生成的,但我没有得到响应,因为我没有经过身份验证。我知道我需要OAuth凭据,但我不确定具体在哪里设置这些凭据(我已经有了我的客户端id和密码) 这是我的代码,在Javascript 无法在Meteor-OAuth问题中使用Google日历API?,javascript,meteor,google-api,google-calendar-api,google-oauth,Javascript,Meteor,Google Api,Google Calendar Api,Google Oauth,我正在开发一个使用GoogleCalendarAPI的web应用程序(目前,我只希望能够从日历中检索和显示事件列表),但我还不能正确地调用API。从技术上讲,它是生成的,但我没有得到响应,因为我没有经过身份验证。我知道我需要OAuth凭据,但我不确定具体在哪里设置这些凭据(我已经有了我的客户端id和密码) 这是我的代码,在body.js中: import { Template } from 'meteor/templating'; import { HTTP } from 'meteor/htt
body.js
中:
import { Template } from 'meteor/templating';
import { HTTP } from 'meteor/http'
import './body.html';
Template.body.helpers({
test() {
HTTP.get("https://www.googleapis.com/calendar/v3/calendars/michelleran707@gmail.com/events", function(error, response) {
console.log(response);
});
},
});
在body.html
中,我使用{{test}
在随机位置调用test
。(我不确定这是不是正确的代码,因为我是Meteor的新手。)
至于OAuth,我四处搜索,最后使用的代码是:
import { Accounts } from 'meteor/accounts-base'
Accounts.loginServiceConfiguration.remove({
service: "google"
});
Accounts.loginServiceConfiguration.insert({
service: "google",
clientId: "my id",
secret: "my secret"
});
我已经将这两个JavaScript文件导入了
main.js
。但是,我仍然无法正确地进行API调用。我遗漏了什么?解决了-我修改了官方的代码,使OAuth正常工作。似乎一开始我就忽略了这一点。您肯定需要auth。但是首先,您不能从客户端进行同步HTTP调用。所以您应该将您的console.log
放在异步回调中。好的,修复了这个问题。现在问题似乎实际上来自OAuth。