我正在尝试在 Google App Engine 中完成学校报纸的故事分配系统。它将跟踪作家的截止日期,允许作家挑选故事,并“一目了然”地查看每周的故事。我和我的合作伙伴正在尝试将它与我们的报纸 Google Apps 安装完全集成。哦,我们必须使用 3 条腿的 Oauth,因为我们没有 Google Apps Premier。
在那次努力中,我偶然发现了 Aeoid,并且能够按照说明进行联合登录。这很酷!
我遇到麻烦的地方是使用 Oauth 获取用户 google 文档列表。我在这里设置了一个测试页面:mustrun.cornellsun.com/test。它给我错误 - 我已将它们复制到这封邮件的底部。我不知道这是否与我的消费者 secret 有关(我应该使用从谷歌市场获得的 key 吗?还是应该使用从管理域页面获得的 key ?)。现在我正在使用从管理域页面获得的 key
还有一个问题是,实际的 appspot 域是 mustrun2sun [].appspot[too new can't post more并且还可以将应用程序部署在我的域中。 (应用程序部署为 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)))
我一直在网上四处寻找答案,但一直找不到。
最佳答案
我有一个使用 OpenID 和 OAuth 来获取您的 google 联系人的 python App Engine 应用程序:
http://github.com/sje397/Chess
它运行于:
请注意,不再需要 Aeoid,因为 App Engine 有 built-in OpenID支持。
关于python - Oauth + Aeoid +Python + Google App Engine + Google 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2835908/