问题描述
我正在尝试使用apigoogle node.js客户端库访问Google Drive API,以便我可以将某些文件上传到驱动器帐户.
到目前为止我的代码:
var drive = google.drive({ version: 'v3' }); drive.apiKey = "API_KEY" drive.setScope = "https://www.googleapis.com/auth/drive.file" drive.files.create({ resource: { name: 'text.text', mimeType: 'text/plain', parents:['1ATscm2nsE9KpjA66iXHB9jnMrbyik7PP'] }, media: { mimeType: 'text/plain', body: fs.createReadStream('files/text.text') } });
错误:
errors: [ { domain: 'global', reason: 'required', message: 'Login Required', locationType: 'header', location: 'Authorization' } ] }
任何人都可以帮助解决这个问题吗?
推荐答案
您可以使用此线程a>.确保您要发送access_token={your oauth2 access token}而不是key={your key}用于访问令牌.您可以检查此文档有关更多信息.
问题描述
I am trying to use apiGoogle Node.js client library to access the Google Drive API so I can upload some files to my drive account.
My code so far:
var drive = google.drive({ version: 'v3' }); drive.apiKey = "API_KEY" drive.setScope = "https://www.googleapis.com/auth/drive.file" drive.files.create({ resource: { name: 'text.text', mimeType: 'text/plain', parents:['1ATscm2nsE9KpjA66iXHB9jnMrbyik7PP'] }, media: { mimeType: 'text/plain', body: fs.createReadStream('files/text.text') } });
Errors:
errors: [ { domain: 'global', reason: 'required', message: 'Login Required', locationType: 'header', location: 'Authorization' } ] }
Can anybody help to resolve this issue?
推荐答案
You may refer with this thread. Make sure that you are sending access_token={your oauth2 access token} and not key={your key} for an access token. You may check this documentation for more information.