python google drive api_Google Drive API authentication, JavaScript

问题

I am running on a virtual host (as well as a Python SimpleHTTPServer) and I have been following Google's instructions, but I can't get the Google drive authorization to pop up on page refresh.

https://developers.google.com/drive/web/auth/web-client

Ive placed the first block of code in my index.html file, and Ive placed the following 2 snippets in

var CLIENT_ID = '1052173400541-355uhjrflurk7fmlon0r5umnn12i9ag3.apps.googleusercontent.com';

var SCOPES = [

'https://www.googleapis.com/auth/drive.file',

'email',

'profile',

// Add other scopes needed by your application.

];

/**

* Called when the client library is loaded.

*/

function handleClientLoad() {

checkAuth();

}

/**

* Check if the current user has authorized the application.

*/

function checkAuth() {

gapi.auth.authorize(

{'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': true},

handleAuthResult);

}

/**

* Called when authorization server replies.

*

* @param {Object} authResult Authorization result.

*/

function handleAuthResult(authResult) {

if (authResult) {

// Access token has been successfully retrieved, requests can be sent to the API

} else {

// No access token could be retrieved, force the authorization flow.

gapi.auth.authorize(

{'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': false},

handleAuthResult);

}

}

welcome to google_drive.local

/**

* Load the Drive API client.

* @param {Function} callback Function to call when the client is loaded.

*/

function loadClient(callback) {

gapi.client.load('drive', 'v2', callback);

}

/**

* Print a file's metadata.

*

* @param {String} fileId ID of the file to print metadata for.

*/

function printFile(fileId) {

var request = gapi.client.drive.files.get({

'fileId': fileId

});

request.execute(function(resp) {

if (!resp.error) {

console.log('Title: ' + resp.title);

console.log('Description: ' + resp.description);

console.log('MIME type: ' + resp.mimeType);

} else if (resp.error.code == 401) {

// Access token might have expired.

checkAuth();

} else {

console.log('An error occured: ' + resp.error.message);

}

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值