How to get all files of all users using google drive API

喜你入骨 提交于 2019-12-18 08:56:55

问题


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)

回答1:


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



来源:https://stackoverflow.com/questions/13727206/how-to-get-all-files-of-all-users-using-google-drive-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!