如何使用 api 密钥访问 Google Drive

编程入门 行业动态 更新时间:2024-10-06 10:36:50
本文介绍了如何使用 api 密钥访问 Google Drive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试使用 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/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 02:59:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/928355.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密钥   如何使用   Drive   api   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!