【问题标题】:How to get all files of all users using google drive API如何使用谷歌驱动API获取所有用户的所有文件
【发布时间】:2012-12-05 15:55:52
【问题描述】:

我是 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)

【问题讨论】:

标签: admin google-drive-api service-accounts


【解决方案1】:

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

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

【讨论】:

  • 感谢克劳迪奥,我也尝试过 clientDocs clientDocs = gdata.docs.service.DocsService() (并在上面编辑了我的脚本以显示这一点)但是,每个用户返回的“密码”是始终为“无”,因此 clientLogin 返回错误的身份验证。想法?
  • 出于安全原因,您无法使用 API 检索用户的密码。一般来说,您永远不应该向其他用户询问他们的凭据,您应该做的事情记录在我的回复中的链接中。
  • 您好克劳迪奥,感谢您的回复。我放弃了驱动委托方式,因为 Python 无法导入“SignedJwtAssertionCredentials”。我将尝试移植到 Java,看看效果如何。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多