【问题标题】:Android App + Cordova + HTML5 + Google Drive ApiAndroid 应用 + Cordova + HTML5 + Google Drive Api
【发布时间】:2016-06-13 03:36:24
【问题描述】:

我开发了一个 html5 页面来列出 google 驱动器文件并使用 PhoneGap 服务器进行测试。一切正常,因为我创建了一个配置了 http://localhost:3000 的 Oauth2。

当我尝试使用 SHA1(也在 google drive 控制台中的 Oauth2 上配置)测试 APK 文件时,我收到了错误:

Refused to display 'https://accounts.google.com/o/oauth2/auth?client_id=<KEY>' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. I understand that this error is because the Oauth2 doesn't expect the origin. But the Origin is not http, if file know... (file:///android_asset/www/index.html). The GoogleAPI Console doesn't accept 'file' protocol... just 'http'.

我该如何解决这个问题?

【问题讨论】:

  • 你可以通过类似的 SO question查看我的答案

标签: android html cordova google-drive-api


【解决方案1】:

根据此 SO 帖子中给出的解决方案 - Refused to display in an frame because it set 'X-Frame-Options' to 'SAMEORIGIN',关于遇到的错误:

这与禁用 chrome 浏览器中的安全性无关。我相信我的 XAMPP Windows 本地主机可能存在一些问题。在 node.js 服务器中部署相同的应用程序或将 Dropbox/Google Drive 托管为 Web 应用程序也可以正常工作。

此外,要发出请求,如在使用 OAuth 2.0 访问 Google API 中从basic steps 的第 2 步中所述,请从 Google 授权服务器获取访问令牌。提出请求的方式如下:

  • JavaScript 应用程序可能会使用浏览器重定向到 Google 来请求访问令牌
  • 安装在没有浏览器的设备上的应用程序使用网络服务请求。

您可以使用的示例场景可以在文档中找到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多