Google Drive API Python服务帐户示例

编程入门 行业动态 更新时间:2024-10-07 18:21:57
本文介绍了Google Drive API Python服务帐户示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以使用Google服务帐户而不是OAuth流针对Google Drive API进行身份验证?

Is it possible to authenticate against the Google Drive API using a Google Service Account, rather than an OAuth flow ?

Google云端硬盘的Python示例使用OAuth- Google云端硬盘Python快速入门

The Python examples for Google Drive use OAuth - Google drive Python Quick start

但是我找不到任何服务帐户示例.

However I can't find any Service Account examples.

我使用的其他大多数Google API(翻译,Cloud Vision)使用都使用服务帐户,因此,为了保持一致性,我想弃用我的Google Drive OAuth代码.

The majority of the other Google APIs I use (Translate, Cloud Vision) do use Service Account however, so I'd like to deprecate my Google Drive OAuth code for consistency.

推荐答案

我知道的最佳服务帐户python示例是 Google Analytics(分析)

The best service account python example that i know of is the one for Google analytics

应该是这样的.

from apiclient.discovery import build from oauth2client.service_account import ServiceAccountCredentials SCOPES = ['www.googleapis/auth/drive.readonly'] KEY_FILE_LOCATION = '<REPLACE_WITH_JSON_FILE>' VIEW_ID = '<REPLACE_WITH_VIEW_ID>' def initialize_drive(): """Initializes an service object. Returns: An authorized service object. """ creds = ServiceAccountCredentials.from_json_keyfile_name( KEY_FILE_LOCATION, SCOPES) # Build the service object. service = build('drive', 'v3', credentials=creds) return service

一旦有了驱动器服务,您就应该能够使用其他教程中剩下的代码.只是不同的auth方法.

Once you have the drive service you should be able to use the rest of the code you have from the other tutorial. Its just the auth method that is diffrent.

仅记得创建服务帐户凭据而不是Oauth凭据.

Just remember to create service account credentials and not Oauth credentials.

更多推荐

Google Drive API Python服务帐户示例

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

发布评论

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

>www.elefans.com

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