如何使用谷歌驱动器API获取所有用户的所有文件 [英] How to get all files of all users using google drive API

查看:174
本文介绍了如何使用谷歌驱动器API获取所有用户的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google帐户的'域名管理员',希望:
获取我的域中的所有用户和为每个用户,让其他用户读取访问所有人的文件。我可以得到每个用户,但现在我不明白如何获取每个用户文档。

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

userNameAtGmailCom ='domainAdmin@someplace.com'
密码='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 all_users.entry中的用户:
user_name = user.login.user_name
打印user_name
password = user.login.password
打印密码
clientDocs = gdata.docs.service.Do csService()
#password总是返回'none'
#因此,如果下面的行运行
#clientDocs,那么我已经将'bad authentication'
#注释掉了。 ClientLogin(user_name,密码)
#documents_feed = clientDocs.GetDocumentListFeed()
#documents_feed.entry中的document_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,角色=角色)
#created_acl_entry = client.Post(acl_entry,document_entry.GetAclLink().href,converter = gdata.docs.DocumentListAclEntryFromString)

login(userNameAtGmailCom,password,personToShareWith,domain )


解决方案

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

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


I am a 'domain admin' for a google account and would like to: Get all of the users in my domain and "for each" user, give another user read-access everyone's files . I can get each user, but right now I do not understand how to get each users documents.

#!/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)

解决方案

You should use the Google Drive API and use service accounts to perform Google Apps domain-wide delegation of authority:

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

这篇关于如何使用谷歌驱动器API获取所有用户的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆