如何使用 api 密钥访问 Google Drive [英] How to use api key to access the Google Drive

查看:74
本文介绍了如何使用 api 密钥访问 Google Drive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 apiGoogle Node.js 客户端库来访问 Google Drive API,以便我可以将一些文件上传到我的驱动器帐户.

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.

到目前为止我的代码:

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' } ] }

有人可以帮忙解决这个问题吗?

Can anybody help to resolve this issue?

推荐答案

你可以参考这个线程.确保您发送的是 access_token={your oauth2 access token} 而不是 key={your key} 作为访问令牌.您可以查看此文档了解更多信息.

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.

这篇关于如何使用 api 密钥访问 Google Drive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆