javascript – 在网页上显示来自Google云端硬盘的文档
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 在网页上显示来自Google云端硬盘的文档,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3255字,纯文字阅读大概需要5分钟。
内容图文
![javascript – 在网页上显示来自Google云端硬盘的文档](/upload/InfoBanner/zyjiaocheng/756/744aa27996a94bd6bc17cd25ba28a28d.jpg)
是否可以在网页上显示我的驱动器中的文档?我希望用户能够直接从我的驱动器单击文档并下载它.我该怎么做呢?谢谢你的建议.
解决方法:
对于HTML / JavaScript解决方案,请查看以下链接:
https://developers.google.com/drive/quickstart-js
https://www.youtube.com/watch?v=09geUJg11iA
https://developers.google.com/drive/web/auth/web-client
这是使用JavaScript的最简单方法,大部分复杂性都在于
您的WebApp授权.下面的示例读取您指定的文件夹中的文件ID,名称和描述.
– 转到:https://cloud.google.com/console/project
并创建一个新项目“xyz”
– 选择“API& auth”,禁用您不需要的,启用“Drive API”
– 选择“凭据”,
按“创建新客户端ID”按钮
x Web应用程序
授权Javascript起源:“https://googledrive.com/”
授权重定向URI:“https://googledrive.com/oauth2callback”
它会导致:
客户ID:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
电子邮件地址:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com
客户机密:xxxxxxxxxxxxxxxxxxxx
重定向URI:https://googledrive.com/oauth2callback
Javascript起源:https://googledrive.com/
– 在下面的代码中,替换
CLIENT_ID with xxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
FOLDER_ID与您在文件夹地址行中看到的ID,
https://drive.google.com/?tab=mo&authuser=0#folders/xxxxxxxxxxxxxxxxxxx
– 运行它,授权
我不知道你是否读过JS,代码可以自下而上,我做的就是尽可能简单.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
var FOLDER_ID = '.xxxxxxxxxxxxxxxxxx'; // the folder files reside in
var CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com';
var SCOPE = //'https://www.googleapis.com/auth/drive';
[
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file', // for description,
];
function rsvpCB(resp) {
var picAlbumLst = '<ul>\n';
for (i=0; i<resp.items.length; i++)
picAlbumLst += (
' <li>'+resp.items[i].id+', '+resp.items[i].title+', '+resp.items[i].description+'</li>\n');
picAlbumLst += "</ul>\n";
$('#container').append(picAlbumLst);
}
function rqstCB() { //test @ https://developers.google.com/drive/v2/reference/files/list
var rv = gapi.client.drive.files.list({
'q': '"'+FOLDER_ID+'" in parents and trashed = false',
'fields' : 'items(id,title,description)' //'items(id,title,description,indexableText)'
}).execute(rsvpCB);
}
// authorization server reply
function onAuthResult(authResult) {
var authButton = document.getElementById('authorizeButton');
authButton.style.display = 'none';
if (authResult && !authResult.error) { // access token successfully retrieved
gapi.client.load('drive', 'v2', rqstCB);
} else { // no access token retrieved, force the authorization flow.
authButton.style.display = 'block';
authButton.onclick = function() {
checkAuth(false);
}
}
}
// check if the current user has authorized the application.
function checkAuth(bNow) {
gapi.auth.authorize({'client_id':CLIENT_ID, 'scope':SCOPE, 'immediate':bNow}, onAuthResult);
}
// called when the client library is loaded, look below
function onl oadCB() {
checkAuth(true);
}
</script>
<script src="https://apis.google.com/js/client.js?onload=onLoadCB"></script>
<body style="background-color: transparent;">
<input type="button" id="authorizeButton" style="display: none" value="Authorize" />
<div id="container">
</div>
</body>
内容总结
以上是互联网集市为您收集整理的javascript – 在网页上显示来自Google云端硬盘的文档全部内容,希望文章能够帮你解决javascript – 在网页上显示来自Google云端硬盘的文档所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。