我進一步得到:
使用Node包「谷歌OAuth的智威湯遜」我已經成功地驗證了我的請求,並接收返回的訪問令牌。
var googleAuth = require('google-oauth-jwt');
// obtain a JWT-enabled version of request
var request = googleAuth.requestWithJWT();
var TokenCache = googleAuth.TokenCache;
var tokens = new TokenCache();
tokens.get({
// use the email address of the service account, as seen in the API console
email: 'google-generated-email',
// use the PEM file we generated from the downloaded key
keyFile: 'pemfile.pem',
// specify the scopes you wish to access
scopes: ['https://www.googleapis.com/auth/drive.readonly']
}, function (err, token) {
console.log('Google API with JWT Request');
console.log('---------------------------');
console.log('The GoogleDrive Token is : ' + token);
});
googleAuth.authenticate({
// use the email address of the service account, as seen in the API console
email: 'google-generated-email',
// use the PEM file we generated from the downloaded key
keyFile: 'pemfile.pem',
// specify the scopes you wish to access
scopes: ['https://www.googleapis.com/auth/drive.readonly']
}, function (err, token) {
console.log('Google API: Authenticated');
console.log('------------------------');
console.log('The GoogleDrive Token is : ' + token);
});
另一件事谷歌與OAuth的智威湯遜可以是使用JWT發送一個請求 - 但我對咖啡低或並不真正理解什麼回來了(可能是後者)。
我用下面的代碼發出請求:
request({
url: 'https://www.googleapis.com/drive/v2/files',
jwt: {
// use the email address of the service account, as seen in the API console
email: 'google-generated-email',
// use the PEM file we generated from the downloaded key
keyFile: 'pemfile.pem',
// specify the scopes you wish to access - each application has different scopes
scopes: ['https://www.googleapis.com/auth/drive.readonly']
}
}, function (err, res, body) {
console.log(JSON.parse(body));
});
的CONSOLE.LOG產生如下:
{ kind: 'drive#fileList',
etag: '"fk0AzBEIhUhhdZ8fZzKcL1hA5NE/oop8mnyogpISt5nktdy1MHxUDnc"',
selfLink: 'https://www.googleapis.com/drive/v2/files',
items:
[ { kind: 'drive#file',
id: '0B1ka-zLvU5tjc3RhcnRlcl9maWxl',
etag: '"fk0AzBEIhUhhdZ8fZzKcL1hA5NE/MTQxMDM1MTI0MTkzOA"',
selfLink: 'https://www.googleapis.com/drive/v2/files/0B1ka-zLvU5tjc3RhcnRlcl9maWxl',
webContentLink: 'https://docs.google.com/uc?id=0B1ka-zLvU5tjc3RhcnRlcl9maWxl&export=download',
alternateLink: 'https://docs.google.com/file/d/0B1ka-zLvU5tjc3RhcnRlcl9maWxl/edit?usp=drivesdk',
iconLink: 'https://ssl.gstatic.com/docs/doclist/images/icon_10_pdf_list.png',
thumbnailLink: 'https://lh6.googleusercontent.com/[somestuff]_ZFIkWw-che6o=s220',
title: 'How to get started with Drive',
mimeType: 'application/pdf',
labels: [Object],
createdDate: '2014-09-10T12:14:01.938Z',
modifiedDate: '2014-09-10T12:14:01.938Z',
markedViewedByMeDate: '1970-01-01T00:00:00.000Z',
version: '6',
parents: [Object],
downloadUrl: 'https://doc-0s-b4-docs.googleusercontent.com/docs/securesc/[somestuff]/0B1ka-zLvU5tjc3RhcnRlcl9maWxl?h=16653014193614665626&e=download&gd=true',
userPermission: [Object],
originalFilename: 'How to get started with Drive',
fileExtension: '',
md5Checksum: '2f215372c903f401e9e101d1d531e5dd',
fileSize: '3017667',
quotaBytesUsed: '0',
ownerNames: [Object],
owners: [Object],
lastModifyingUserName: '',
lastModifyingUser: [Object],
editable: true,
copyable: true,
writersCanShare: true,
shared: false,
appDataContents: false } ] }
我試圖讓從一個 'children.list'文件夾(無論是根目錄還是文件夾ID) - 但這不是它。有沒有人有這種方法訪問文件夾列表的任何想法?
感謝您的幫助:)
嗨:) - 欣賞你說,但我真的不能看到谷歌Drive..so連接中使用谷歌,OAuth的智威湯遜這進一步,但不是最終得到了我至今。感謝您的想法:) – Pandafinity 2014-09-11 12:35:27