【发布时间】:2017-03-04 11:08:52
【问题描述】:
我在我的 AngularJS 项目中使用 Google Discovery API 来支持 Google OAuth。我使用this URL,然后使用相应的discoveryRestUrl 来获取API 范围。
一切正常,直到我使用 Google 表格的 discoveryRestUrl 即 https://sheets.googleapis.com/$discovery/rest?version=v4 尝试上述操作。
我使用 Angular 的 $http 服务来触发 GET 请求以获取 API 特定信息。在我的浏览器控制台中,我看到两个请求正在生成——一个是使用OPTIONS 方法(预检),第二个是使用GET 方法(它获取 JSON 数据)。
对于表格,在发出预检请求时,我在浏览器的控制台中收到以下错误。
XMLHttpRequest cannot load https://sheets.googleapis.com/$discovery/rest?version=v4. Response to preflight request doesn't pass access control check: Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials. Origin 'http://localhost:3000' is therefore not allowed access.
我没有看到其他 API 存在此类问题。我尝试用我的浏览器和 cURL 触发相同的 URL,但它们工作正常。
请帮忙!
【问题讨论】:
标签: angularjs cors google-sheets-api