如何触发点击“保存到Google云端硬盘"按钮 [英] How to trigger click on "Save to Google Drive" button
本文介绍了如何触发点击“保存到Google云端硬盘"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何触发保存到Google云端硬盘"按钮的点击",我的意思是,我有自己的保存到Google云端硬盘"按钮设计.是否有任何以编程方式触发的用Javascript打开保存到Google驱动器"弹出窗口?
How to trigger "click" on Save to Google Drive button, i mean, i have my own design for "Save to Google Drive" button. is there any programaticly trigger to open "save to google drive" popups in 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()".
As you can see, the handleAuthResult()
get the OAuth result and conditionally check the authorization then if successful will add onclick="uploadFile()".
这篇关于如何触发点击“保存到Google云端硬盘"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文