如何触发点击“保存到Google云端硬盘”按钮
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何触发点击“保存到Google云端硬盘”按钮相关的知识,希望对你有一定的参考价值。
如何在“保存到Google云端硬盘”按钮上触发“点击”,我的意思是,我有自己的“保存到Google云端硬盘”按钮设计。是否有任何编程触发器在javascript中打开“保存到谷歌驱动器”弹出窗口?
谢谢
编辑
我想修改这个API
https://developers.google.com/drive/v3/web/savetodrive#getting_started
答案
你可以试试:
html:
<html>
<head>
<title>Save to Drive</title>
</head>
<body>
<input type="button" id="doitButton" value="Save Chat History in Drive">
<input type="button" id="authorizeButton" value="Authorize" onClick="checkAuth()">
<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
</body>
</html>
JS:
var CLIENT_ID = 'CLIENT_ID';
var SCOPES = 'https://www.googleapis.com/auth/drive';
function handleClientLoad() {
window.setTimeout(checkAuth, 1);
}
function checkAuth() {
gapi.auth.authorize({
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': true
}, handleAuthResult);
}
function handleAuthResult(authResult) {
var authButton = document.getElementById('authorizeButton');
var doitButton = document.getElementById('doitButton');
authButton.style.display = 'none';
doitButton.style.display = 'none';
if (authResult && !authResult.error) {
// Access token has been successfully retrieved, requests can be sent to
// the API.
doitButton.style.display = 'block';
doitButton.onclick = uploadFile;
} else {
// No access token could be retrieved, show the button to start the
// authorization flow.
authButton.style.display = 'block';
authButton.onclick = function() {
gapi.auth.authorize({
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': false
}, handleAuthResult);
};
}
}
function uploadFile(evt) {
gapi.client.load('drive', 'v2', function() {
insertFile();
});
}
function insertFile() {
//YOUR INSERT CODE
}
如您所见,handleAuthResult()
获取OAuth结果并有条件地检查授权,然后如果成功将添加onclick =“uploadFile()”。
以上是关于如何触发点击“保存到Google云端硬盘”按钮的主要内容,如果未能解决你的问题,请参考以下文章
来自GmailApp附件的DriveApp createFile无法正常工作
JAVA Eclipse 如何点击一个按钮就触发另外一个CLASS程序