2012-04-12 119 views
1

使用管理权限/模拟(禁止403)下载用户文件我看了这个彻底:https://developers.google.com/google-apps/documents-list/#using_google_apps_administrative_access_to_impersonate_other_domain_users 我用Google搜索这个死亡。谷歌文档:无法导出/ Python中

到目前为止,我已经能够:

  1. 授权使用:

    • 的ClientLogin
    • OAuth凭证(使用我的域密钥)
  2. 检索文档供稿对于域中的所有用户(在#1中以任一方式授权)
    我正在使用Feed中的“条目”导出/下载文档,并且始终禁止其他用户查看未与管理员共享的文档。我使用的进料的查询是这样的: https://docs.google.com/feeds/[email protected]/private/full/?v=3 (?我已经有和没有试图V = 3)

我还试图加入xoauth_requestor_id(我还看到在帖子为xoauth_requestor) ,无论在URI,并作为一个客户端特性:client.xoauth_requestor_id = ...

代码片段:

客户端登录(使用管理员凭据):

client.http_client.debug = cfg.get('HTTPDEBUG') 
client.ClientLogin(cfg.get('ADMINUSER'), cfg.get('ADMINPASS'), 'HOSTED') 

的OAuth:

client.http_client.debug = cfg.get('HTTPDEBUG') 
client.SetOAuthInputParameters(gdata.auth.OAuthSignatureMethod.HMAC_SHA1, cfg.get('DOMAIN'), cfg.get('APPS.SECRET')) 
oatip = gdata.auth.OAuthInputParams(gdata.auth.OAuthSignatureMethod.HMAC_SHA1, cfg.get('DOMAIN'), cfg.get('APPS.SECRET')) 
oat = gdata.auth.OAuthToken(scopes = cfg.get('APPS.%s.SCOPES' % section), oauth_input_params = oatip) 
oat.set_token_string(cfg.get('APPS.%s.TOKEN' % section)) 
client.current_token = oat 

Feed后检索:

# pathname eg whatever.doc 
client.Export(entry, pathname) 
# have also tried 
client.Export(entry, pathname, extra_params = { 'v': 3 }) 
# and tried 
client.Export(entry, pathname, extra_params = { 'v': 3, 'xoauth_requestor_id': '[email protected]' }) 

任何建议或指针来什么,我在这里失踪? 谢谢

+0

如果对这一问题的回答,可以将其标记回答?另外,请发布一个新问题,并附上步骤来重现您在评论中提到的其他401s/403s。 – 2012-04-13 12:56:24

回答

1

你非常接近正确的实施。在你上面的例子中,你有:

client.Export(entry, pathname, extra_params = { 'v': 3, 'xoauth_requestor_id': '[email protected]' }) 

xoauth_requestor_id必须设置给你模拟的用户。此外,您需要使用2-Legged OAuth 1.0a以及在令牌或客户端中设置的xoauth_requestor_id。

import gdata.docs.client 
import gdata.gauth 

import tempfile 


# Replace with values from your Google Apps domain admin console 
CONSUMER_KEY = '' 
CONSUMER_SECRET = '' 

# Set this to the user you're impersonating, NOT the admin user 
username = '[email protected]' 
destination = tempfile.mkstemp() 

token = gdata.gauth.TwoLeggedOAuthHmacToken(
    consumer_key, consumer_secret, username) 
# Setting xoauth_requestor_id in the DocsClient constructor is not required 
# because we set it in the token above, but I'm showing it here in case your 
# token is constructed via some other mechanism and you need another way to 
# set xoauth_requestor_id. 
client = gdata.docs.client.DocsClient(
    auth_token=token, xoauth_requestor_id=username) 
# Replace this with the resource your application needs 
resource = client.GetAllResources()[0] 
client.DownloadResource(resource, path) 
print 'Downloaded %s to %s' % (resource.title.text, destination) 

这里是在源代码中的TwoLeggedOAuthHmacToken类参考:

  1. http://code.google.com/p/gdata-python-client/source/browse/src/gdata/gauth.py#1062

这里是源代码,提供xoauth_requestor_id构造函数的参数引用(读这些按顺序):

  1. http://code.google.com/p/gdata-python-client/source/browse/src/atom/client.py#42
  2. http://code.google.com/p/gdata-python-client/source/browse/src/atom/client.py#179
  3. http://code.google.com/p/gdata-python-client/source/browse/src/gdata/client.py#136
+0

谢谢Vic。现在取得更大的成功。还有一些401或403的文件,但它可能是另一个原因 – 2012-04-13 12:17:10