简体   繁体   English

从AngularJS APP访问Google Calendar API

[英]Accessing Google Calendar API from AngularJS APP

I am implementing (I am trying to implement) a 100% client side AngularJS web app which should access the google calendar API. 我正在实现(我正在尝试实现)应该访问Google Calendar API的100%客户端AngularJS Web应用程序。 Of course, this doesn't work because I hit the cross domain problem: 当然,这不起作用,因为我遇到了跨域问题:

XMLHttpRequest cannot load http://... . Origin http://localhost:9000 is not allowed by Access-Control-Allow-Origin.

Is there any solution to bypass this issue, except creating a proxy? 除了创建代理之外,是否有任何解决方案可以绕过此问题? By setting some header or changing some google configuration? 通过设置一些标题或更改一些google配置? I don't see one ... 我看不到...

Great hint Philipp! 菲利普很有暗示! The google javascript api client ( see here ) does the job. google javascript api客户端( 请参阅此处 )完成了这项工作。

But I am wondering: How does the google javascript api client bypasses the cross domain issue? 但是我想知道:google javascript api客户端如何绕过跨域问题? Does someone know? 有人知道吗

You need googles side to return the right headers, Access-Control-Allow-Origin, to your browser so it doesnt complain about the cross browser issue. 您需要在google方面将正确的标题Access-Control-Allow-Origin返回到您的浏览器,以便它不会抱怨跨浏览器的问题。

Make sure in the google cloud console is configured correctly to web application. 确保在Google Cloud Console中正确配置了Web应用程序。 Im assuming web app because the redirect though. 我假设网络应用程序,因为虽然重定向。

If its a phoneapp or not serving anything on localhost:9000 redirect endpoint there are other options. 如果它的phoneapp或在localhost:9000重定向端点上不提供任何服务,则还有其他选项。 For example you could open up the oauth redirect in another window, still use localhost:9000 as the redirect. 例如,您可以在另一个窗口中打开oauth重定向,但仍使用localhost:9000作为重定向。 Even though you are not listening at that port you could still grab the url code or error that is set on the redirect from the parent window. 即使您不在该端口上侦听,您仍然可以从父窗口获取在重定向中设置的url代码或错误。

CORS is an issue that you will experience when running the app through web browsers. 通过Web浏览器运行应用程序时,您会遇到CORS问题。 I suggest you download a CORS toggle extension on google chrome so you can toggle off CORS and the API will connect. 我建议您在Google chrome上下载CORS切换扩展程序,以便您可以关闭CORS并连接API。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM