管理员设置API,在gdata和python中使用oauth2

cpr*_*rod 7 python gdata oauth-2.0 google-admin-settings-api

带有oauth2的管理员设置API

我正在尝试使用OAuth2凭据将使用python编写的应用程序连接到Admin Settings API,但是我收到错误消息:

源代码:

from oauth2client.client import Credentials
import gdata.apps.adminsettings.service
import gdata.gauth

#credentials_json is a string with an oauth2 credential that is saved in datastore
#domain_name is the name of the target domain
#app_name is my application name

credentials = Credentials.new_from_json(credentials_json)
auth2token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
service = gdata.apps.adminsettings.service.AdminSettingsService(source=app_name,domain=domain_name)
service = auth2token.authorize(service)

print service.GetMaximumNumberOfUsers()
Run Code Online (Sandbox Code Playgroud)

例外:

Traceback (most recent call last):
  File "<input>", line 25, in <module>
  File "xxxxxxx\lib\gdata\apps\adminsettings\service.py", line 116, in GetMaximumNumberOfUsers
    result = self.genericGet('general/maximumNumberOfUsers')
  File "xxxxxxx\lib\gdata\apps\adminsettings\service.py", line 50, in genericGet
    return self._GetProperties(uri)
  File "xxxxxxx\lib\gdata\apps\service.py", line 522, in _GetProperties
    str(self.Get(uri))))
  File "xxxxxxx\lib\gdata\service.py", line 1069, in Get
    headers=extra_headers)
  File "xxxxxxx\lib\atom\__init__.py", line 93, in optional_warn_function
    return f(*args, **kwargs)
  File "xxxxxxx\lib\atom\service.py", line 186, in request
    data=data, headers=all_headers)
  File "xxxxxxx\lib\atom\http_interface.py", line 148, in perform_request
    return http_client.request(operation, url, data=data, headers=headers)
TypeError: new_request() takes exactly 1 argument (4 given)
Run Code Online (Sandbox Code Playgroud)

非常感谢您的关注

卡洛斯普列托

小智 0

使用服务帐户身份验证/关键字失败的 AdminSettings API来看,gdata 服务对象似乎不支持 Oauth 2.0 我在使用 gdata 联系人服务对象时遇到了类似的错误,并通过使用联系人客户端对象修复了该错误。管理设置应用程序似乎没有客户端,只有服务,但链接的 stackoverflow 页面有一个解决方法。