2012-04-12 90 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