【发布时间】:2011-02-19 14:58:59
【问题描述】:
我正在尝试在 Google App Engine 中为我的校报完成一个故事分配系统。它将跟踪作家的截止日期,允许作家挑选故事,并“一目了然”地了解每周的故事。我和我的合作伙伴正在尝试将它与我们的报纸 Google Apps 安装完全集成。哦,我们必须使用 3 legged Oauth,因为我们没有 Google Apps Premier。
在那次努力中,我偶然发现了 Aeoid,并能够按照说明进行联合登录。这很酷!
我遇到麻烦的地方是使用 Oauth 获取用户 google 文档的列表。我在这里设置了一个测试页面:mustrun.cornellsun.com/test。它给了我错误 - 我已经在这封邮件的底部复制了它们。我不知道这是否与我的消费者机密有关(我应该使用从谷歌市场获得的密钥?还是应该使用从管理域页面获得的密钥?)。现在我正在使用从管理域页面获得的密钥
另外复杂的是,实际的appspot域是mustrun2sun [].appspot[太新不能发布多个链接].com,但我在谷歌应用程序中设置了它,这样只有我域中的用户才能登录并且还可以将应用程序部署在我的域上。 (应用程序部署为 must[]run[].corn[]ellsun[].[]com 并且所有内容都这样引用它,即使在管理域中也是如此。)
我正在使用 GDClient 2.0 类,所以我相当确定一切都应该按计划进行……也就是说,我没有使用旧的服务或任何东西。我使用htt[]p:/[]/k[]ing[]yo-bachi.blog[]spot.c[]om/2010/05/gaego[]ogleoauth.ht[]ml 作为我的 Oauth“舞蹈”的一个模板,因为 Google 示例已经过时并且使用旧的 Google 数据 1.0 库 - 我认为。
我进入测试页面时遇到的错误是
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 511, in __call__
handler.get(*groups)
File "/base/data/home/apps/mustrun2sun/1.341947133742569880/main.py", line 170, in get
feed = client.GetDocList(auth_token=gdata.gauth.AeLoad(users.get_current_user().user_id())) #auth_token=TOKEN
File "/base/data/home/apps/mustrun2sun/1.341947133742569880/gdata/docs/client.py", line 141, in get_doclist
auth_token=auth_token, **kwargs)
File "/base/data/home/apps/mustrun2sun/1.341947133742569880/gdata/client.py", line 635, in get_feed
**kwargs)
File "/base/data/home/apps/mustrun2sun/1.341947133742569880/gdata/client.py", line 308, in request
response, Unauthorized)
Unauthorized: Unauthorized - Server responded with: 401, <HTML>
<HEAD>
<TITLE>Token invalid - Invalid AuthSub token.</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid - Invalid AuthSub token.</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
另外,由于没有任何源代码,这很难,下面是相关代码:
import gdata.auth
import gdata.gauth
import gdata.docs.client
import gdata.docs.data
import gdata.docs.service
import gdata.alt.appengine
from aeoid import middleware, users
class GetOauthToken(webapp.RequestHandler):
def get(self):
user_id = users.get_current_user().user_id()
saved_request_token = gdata.gauth.AeLoad("tmp_"+user_id)
gdata.gauth.AeDelete ("tmp_" + user_id)
request_token = gdata.gauth.AuthorizeRequestToken(saved_request_token, self.request.uri)
#upgrade the token
access_token = client.GetAccessToken(request_token)
#save the upgraded token
gdata.gauth.AeSave(access_token, user_id)
self.redirect('/test')
class Test(webapp.RequestHandler):
def get(self):
TOKEN = gdata.gauth.AeLoad(users.get_current_user().user_id())
if TOKEN:
client = gdata.docs.client.DocsClient(source=SETTINGS['APP_NAME'])
client.auth_token = gdata.gauth.AeLoad(users.get_current_user().user_id()) #could try to put back as TOKEN?
self.response.out.write('moo baby')
client.ssl = True
feed = client.GetDocList(auth_token=gdata.gauth.AeLoad(users.get_current_user().user_id())) #auth_token=TOKEN
self.response.out.write(feed)
self.response.out.write('moo boobob')
self.response.headers['Content-Type'] = 'text/plain'
for entry in feed.entry:
self.response.out.writeln(entry.title.text)
else:
# Get unauthorized request token
gdata.gauth.AeDelete(users.get_current_user().user_id())
client = gdata.docs.client.DocsClient(source=SETTINGS['APP_NAME'])
client.ssl = True # Force communication through HTTPS
oauth_callback_url = ('http://%s/get_oauth_token' %
self.request.host)
request_token = client.GetOAuthToken(
SETTINGS['SCOPES'], oauth_callback_url, SETTINGS['CONSUMER_KEY'],
consumer_secret=SETTINGS['CONSUMER_SECRET'])
gdata.gauth.AeSave(request_token, "tmp_"+users.get_current_user().user_id())
# Authorize request token
domain = None#'cornellsun.com'
self.redirect(str(request_token.generate_authorization_url(google_apps_domain=domain)))
我一直在网上寻找答案,但一直找不到。
【问题讨论】:
标签: python google-app-engine oauth google-docs