这是我尝试过的所有代码都很好,但当它出现在这个函数下的代码'function makeRequest(){'则代码不执行并停止,我认为响应有问题,此函数获得
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script>
var CLIENT_ID = '988680082729- gudaete5nph93lq1sma15pb9cevi686r.apps.googleusercontent.com';
var API_KEY = 'AIzaSyDPC8gi0zrOFBQmxfgh7rXPU8EQDPe5w-Y';
var SCOPES = 'https://www.googleapis.com/auth/drive';
function handleClientLoad() {
gapi.client.setApiKey(API_KEY);
window.setTimeout(checkAuth,1);
}
function checkAuth() {
var options = {
client_id: CLIENT_ID,
scope: SCOPES,
immediate: true
};
gapi.auth.authorize(options, handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
if (authResult && !authResult.error) {
authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
}
function handleAuthClick(event) {
var options = {
client_id: CLIENT_ID,
scope: SCOPES,
immediate: false
};
gapi.auth.authorize(options, handleAuthResult);
return false;
}
function makeApiCall() {
gapi.client.load('drive', 'v2', makeRequest);
}
function makeRequest() {
var request = gapi.client.drive.files.list({'maxResults': 5 });
request.execute(function(resp) {
for (i=0; i<resp.items.length; i++) {
var titulo = resp.items[i].title;
var fechaUpd = resp.items[i].modifiedDate;
var userUpd = resp.items[i].lastModifyingUserName;
var userEmbed = resp.items[i].embedLink;
var userAltLink = resp.items[i].alternateLink;
var fileInfo = document.createElement('li');
fileInfo.appendChild(document.createTextNode('TITLE: ' + titulo + ' - LAST MODIF: ' + fechaUpd + ' - BY: ' + userUpd ));
document.getElementById('content').appendChild(fileInfo);
}
});
}
$(document).ready(function() {
$('#authorize-button').on('click', handleAuthClick);
$.getScript('//apis.google.com/js/api.js', function() {
gapi.load('auth:client', handleClientLoad);
});
});
</script>
</head>
<body>
<button id="authorize-button">Authorize</button>
<div id="content">Files:</div>
</body>
</html>
您的请求将返回一个对象,当我请求文件列表时,项目位于响应中的结果对象内。尝试在makeRequest()
函数中查找resp.result.items