Google app engine 使用python获取Google应用程序统计信息

Google app engine 使用python获取Google应用程序统计信息,google-app-engine,Google App Engine,我正试图从我的谷歌应用程序生成的谷歌应用统计数据中获取一些网络内容。请注意,这与谷歌分析不同。我正在使用python 2.7.5。 我面临的问题是我请求中的初始google身份验证。 我有需要从google app stats调用的API,但当我使用自己的google appengine帐户凭据时,我不断收到拒绝回复。这将导致重定向到accounts.google.com页面。 我尝试过几种不同的方法,但都没有成功登录accounts.google.com 有人对此有什么想法吗? 如果你能给我指

我正试图从我的谷歌应用程序生成的谷歌应用统计数据中获取一些网络内容。请注意,这与谷歌分析不同。我正在使用python 2.7.5。 我面临的问题是我请求中的初始google身份验证。 我有需要从google app stats调用的API,但当我使用自己的google appengine帐户凭据时,我不断收到拒绝回复。这将导致重定向到accounts.google.com页面。 我尝试过几种不同的方法,但都没有成功登录accounts.google.com

有人对此有什么想法吗? 如果你能给我指一些好的参考资料,我会更有用


谢谢

此代码示例将允许您获取受google登录保护的/secure页面的内容。不要忘记设置电子邮件、密码和应用程序ID。然后,您可以使用此开启器获取其他受保护的页面

import urllib
import urllib2
import cookielib
import logging

EMAIL = ''
PASSWORD = ''
APPID = 'YOURAPPID'

# Setup to be able to get the needed cookies that GAE returns
cookiejar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(opener)

# This is the setup to construct the login URL for authentication.
authreq_data = urllib.urlencode({'Email': EMAIL,
                                 'Passwd': PASSWORD,
                                 'service': 'ah',
                                 'source': '',
                                 'accountType': 'HOSTED_OR_GOOGLE'})

# Get an AuthToken from Google Accounts
auth_req = urllib2.Request('https://www.google.com/accounts/ClientLogin',
                            data=authreq_data)
try:
  auth_resp = opener.open(auth_req)
  logging.info('Successful authorization as %s' % EMAIL)
except urllib2.HTTPError:
  logging.warning('Authorization as %s failed. '
                  'Please, check your email and password' % EMAIL)

auth_resp_body = auth_resp.read()
auth_resp_dict = dict(x.split('=')
                      for x in auth_resp_body.split('\n') if x)
authtoken = auth_resp_dict['Auth']

authreq_data = urllib.urlencode({'continue': 'http://%s.appspot.com/secure' % APPID,
                                 'auth': authtoken})
login_uri = ('http://%s.appspot.com/_ah/login?%s' % (APPID, authreq_data))

# Do the actual login and getting the cookies.
print opener.open(urllib2.Request(login_uri)).read()

嗨,德米特里,非常感谢你的支持,这次活动非常成功。没有太多的资源来解释芬纳的观点,比如你的例子所指出的。如果这个答案真的有帮助的话,请不要忘记接受它。