【发布时间】:2018-06-26 13:50:22
【问题描述】:
我正在使用 Meteor 框架来实现 Google Drive API。我已经生成了clientId、clientSecret和redirectUrl。
在这种方法中,我必须获取 url,当我单击“允许”按钮时,我在重定向 url 中给出了它的重定向 url。它给出了网址中的代码,我已经保存了该代码。
checkForAuthorization = function() {
return new Promise(function(resolve, reject) {
console.log("checkForAuthorization method is running......");
var clientId, clientSecret, redirectUrl, oauth2Client;
clientId = "XYZ";
clientSecret = "ABC";
redirectUrl = "http://localhost:3000/home";
oauth2Client = new google.auth.OAuth2(clientId, clientSecret,
redirectUrl);
getGoogleDriveAccessToken(oauth2Client).then(function(result) {
resolve(result);
}).catch(function(error) {
reject();
});
});
};
此代码用于上传文件。登录给我一个错误,说需要登录。
var uploadFileOnGoogleDrive = function(token) {
return new Promise(function(resolve, reject) {
var fileMetadata = {
'name': 'Claremont-Coral-Pillow-12x241.jpeg'
};
var media = {
mimeType: 'image/jpeg',
body: fs.createReadStream
('/home/administrator/Pictures/Claremont-
Coral-Pillow-12x241.jpeg')
};
drive.files.create({
auth: token,
resource: fileMetadata,
media: media,
fields: 'id'
}, function (err, file) {
if (err) {
console.log("The error is ", err);
} else {
console.log('File Id: ', file.id);
}
});
});
};
我做错了什么?
【问题讨论】:
标签: javascript meteor google-drive-api google-drive-realtime-api