【发布时间】:2015-11-09 23:29:08
【问题描述】:
我正在使用 google drive api 在驱动程序上上传文件,它工作正常。现在我想在我的 Web 应用程序上显示共享对话框。为此,我做了以下事情:
<script type="text/javascript">
var CLIENT_ID = 'Client_ID';
var SCOPES = [
'https://www.googleapis.com/auth/drive',
'email',
'profile',
// Add other scopes needed by your application.
];
/**
* Called when the client library is loaded.
*/
function handleClientLoad() {
checkAuth();
}
/**
* Check if the current user has authorized the application.
*/
function checkAuth() {
gapi.auth.authorize(
{'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': true,'approval_prompt':'auto'},
handleAuthResult);
}
/**
* Called when authorization server replies.
*
* @param {Object} authResult Authorization result.
*/
function handleAuthResult(authResult) {
if (authResult) {
// Access token has been successfully retrieved, requests can be sent to the API
} else {
// No access token could be retrieved, force the authorization flow.
gapi.auth.authorize(
{'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': true},
handleAuthResult);
}
}
<script>
init = function() {
//loadPicker();
gapi.auth.authorize(
{'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': true,'approval_prompt':'auto'},
handleAuthResult);
s = new gapi.drive.share.ShareClient(); s.setOAuthToken('tokan');
s.showSettingsDialog();
s.setItemIds(["<?php echo $_SESSION['file_id']; ?>"]);
}
// window.onload = function() {
function load_set(){
gapi.load('drive-share', init);
}
</script>
现在我收到以下错误:
拒绝在框架中显示,因为它将“X-Frame-Options”设置为“SAMEORIGIN”。
据我阅读 google drive 文档,它说它需要 3 件事:
- 用户已登录 Google
- 用户已安装您的应用
- 启动对话框的页面 URL 必须与为应用注册的打开 URL 具有相同的来源。
我已经使用我的 Google 帐户登录。
我不确定用户如何安装我的应用。我需要在我的页面中添加任何代码吗?
我的网址是一样的。
请清楚地描述这些要点。我在控制台中注意到的一件事是我的客户端 ID 与我上面输入的不同。就像我的客户 ID 是 [123]。
然后在控制台中显示为:
拒绝在框架中显示“https://drive.google.com/sharing/init?id=0B26e8x7MMejoZDRQZm5IOUJvbjQ&forei…nt=postMessage&appId=705048315558&embedOrigin=https%3A%2F%2FMyURL”,因为它将“X-Frame-Options”设置为“SAMEORIGIN”。
需要尽快支持。
非常感谢 高拉夫
【问题讨论】:
-
你编辑了什么@cheryl-simon?
-
您可以通过单击“已编辑”标签来查看。我删除了一个不正确的标签。
标签: javascript php api google-drive-api