我进一步得到:
使用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