admin - 如何使用 google drive API 获取所有用户的所有文件

标签 admin google-drive-api service-accounts

我是 Google 帐户的“域管理员”,我想: 获取我域中的所有用户,并为“每个”用户授予另一个用户读取每个人文件的权限。我可以获取每个用户,但现在我不明白如何获取每个用户的文档。

#!/usr/bin/python
import gdata.docs
import gdata.docs.service
from gdata.apps import client

userNameAtGmailCom = 'domainAdmin@someplace.com'
password           = 'mypassword'
personToShareWith  = "someGuy@gmail.com"
domain             = 'someplace.com'

def login(userNameAtGmailCom, password, personToShareWith, domain):
    client = gdata.apps.client.AppsClient(domain=domain)
    client.ssl = True
    client.ClientLogin(email=userNameAtGmailCom, password=password, source='apps')
    all_users = client.RetrieveAllUsers()
    for user in all_users.entry:
                user_name = user.login.user_name
                print user_name
                password = user.login.password
                print password
                clientDocs = gdata.docs.service.DocsService()
#password always returns 'none' 
#therefore I've commented out the 'bad authentication'
#that would happen if the lines below ran
                #clientDocs.ClientLogin(user_name, password)
                #documents_feed = clientDocs.GetDocumentListFeed()
                #for document_entry in documents_feed.entry:
                #print document_entry.title.text
                #scope = gdata.docs.Scope(value=personToShareWith, type='user')
                #role = gdata.docs.Role(value='reader')
                #acl_entry = gdata.docs.DocumentListAclEntry(scope=scope, role=role)
                #created_acl_entry = client.Post(acl_entry, document_entry.GetAclLink().href, converter=gdata.docs.DocumentListAclEntryFromString)

login(userNameAtGmailCom, password, personToShareWith, domain)

最佳答案

您应该使用 Google Drive API 并使用服务帐户来执行 Google Apps 域范围的授权:

https://developers.google.com/drive/delegation

关于admin - 如何使用 google drive API 获取所有用户的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13727206/

相关文章:

php - 如何在 sonata admin Admin Controller 中设置 flash 消息

iOS - 将(100 多个)文件导出到 Google 云端硬盘

c# - 为什么我得到 System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied

java - 超出 Google Drive API 配额

asp.net - asp.net 上的 AndroidPublisher 库给出错误“未找到给定包名称的应用程序”

python - 如何在 GAE 上使用 Python 中的服务帐户?

kubernetes - ImagePullSecrets GCR

ssl - Glassfish 管理控制台加载空白页

Android:DeviceAdmin 应用程序:无法启动 Activity 以添加设备管理员

admin - Magento2无法创建发票问题