Google Drive API javascript(谷歌驱动 API javascript)
                            本文介绍了谷歌驱动 API javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
我正在尝试使用 Google 驱动器列出文件.
I'm trying to use the Google drive to list files.
使用 https://stackoverflow.com/a/11280257 中的答案,我发现了一个我无法发现的问题原因.
Using the answer in https://stackoverflow.com/a/11280257 I found a problem that I can't discover the reason.
var clientId = '*********.apps.googleusercontent.com';
var apiKey = '##########';
var scopes = 'https://www.googleapis.com/auth/drive';
function handleClientLoad() {
    gapi.client.setApiKey(apiKey);
    window.setTimeout(checkAuth,1);
}
function checkAuth() {
    gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},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) {
    gapi.auth.authorize({client_id: clientId, scope: [scopes], immediate: false}, 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);
        }
    });    
}
我有这个错误:
Uncaught TypeError: Cannot read property 'files' of undefined 
在行中
var request = gapi.client.drive.files.list({'maxResults': 5 });
推荐答案
使用
var request = gapi.client.request({
        'path': '/drive/v2/files',
        'method': 'GET',
        'params': {'maxResults': '1'}
        });
而不是
var request = gapi.client.drive.files.list({'maxResults': 5 });
解决了问题!
这篇关于谷歌驱动 API javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:谷歌驱动 API javascript
				
        
 
            
        
             猜你喜欢
        
	     - 在不使用循环的情况下查找数字数组中的一项 2022-01-01
 - 如何向 ipc 渲染器发送添加回调 2022-01-01
 - 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
 - 如何调试 CSS/Javascript 悬停问题 2022-01-01
 - 为什么我的页面无法在 Github 上加载? 2022-01-01
 - 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
 - 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
 - 如何显示带有换行符的文本标签? 2022-01-01
 - 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
 - 从原点悬停时触发 translateY() 2022-01-01
 
						
						
						
						
						
				
				
				
				