使用服务用户通过电子邮件地址将文件上传到Google云端硬盘 [英] Using Service User to upload files to Google Drive by email address
问题描述
我正在使用服务连接到服务帐户帐户凭据.
我正尝试扩大规模,以供同一公司内的多个用户使用.所有用户都将拥有该公司管理的Google帐户,而我将拥有整个公司的gsuite服务帐户.如何使用gsuite服务帐户根据电子邮件地址将文件上传到用户的个人Google云端硬盘?
I'm trying to scale this up to be used for multiple users within the same company. All users will have Google accounts managed by this company, and I will have a gsuite service account for the entire company. How can I upload a file to users personal Google Drive based on an email address using a gsuite service account?
推荐答案
您要使用ServiceAccountCredential
,并且将User
属性设置为适当的用户.
You want to use ServiceAccountCredential
, with a User
property set to the appropriate user.
假设您正在使用GoogleCredential
加载凭据,这并不难.例如:
Assuming you're loading the credentials using GoogleCredential
, this isn't too hard. For example:
GoogleCredential credential = Google.GetApplicationDefault()
.CreateScoped(...)
.CreateWithUser("foo@bar.com");
如果您想对许多不同的用户使用相同的原始凭据,则可以保留CreateScoped(...)
的结果,而只需调用CreateWithUser
为每个操作创建一个新的特定于用户的凭据.
If you wanted to use the same original credentials for many different users, you could keep the result of CreateScoped(...)
around, and just call CreateWithUser
to create a new user-specific credential for each operation.
这篇关于使用服务用户通过电子邮件地址将文件上传到Google云端硬盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!