Oauth Aeoid Python Google App Engine Google文档

我正在尝试在Google App Engine中为我的学校报纸完成一个故事分配系统.它将追踪作家的截止日期,允许作家收集故事,并对周故事进行“一目了然”的观察.我和我的合作伙伴正试图将它与我们的报纸Google Apps安装完全整合.哦,我们必须使用3条腿的Oauth,因为我们没有Google Apps Premier.

在那次努力中,我偶然发现了Aeoid并且能够按照说明进行联合登录工作.这很酷!

我遇到麻烦的地方是使用Oauth获取用户谷歌文档的列表.我在这里设置了一个测试页面:mustrun.cornellsun.com/test.它给了我错误 – 我已经将它们复制到这封邮件底部.我不知道这是否与我的消费者秘密有关(我应该使用从谷歌市场获得的密钥?还是应该使用我从管理域页面获得的密钥?).现在我正在使用我从管理域页面获得的密钥

同样复杂的是,实际的appspot域是mustrun2sun [] .appspot [太新了不能发布多个链接] .com,但我在google应用程序中设置它,以便只有来自我的域的用户才能登录以便应用程序部署在我的域上. (应用程序部署为必须[]运行[].corn [] ellsun [].[] com&所有内容都指向它,即使在管理域中也是如此.)

我正在使用GDClient 2.0类,所以我很确定一切都应该按计划运行…即我没有使用旧的服务或任何东西.我用了[] p:/ [] / k [] ing [] yo-bachi.blog [] spot.c [] om / 2010/05 / gaego [] ogleoauth.ht [] ml作为一点点我的Oauth“舞蹈”的模板,因为谷歌的例子已经过时了使用旧的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,

此外,由于这对任何源代码都很难,下面是相关代码

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 App Engine应用程序,它使用OpenID和OAuth来获取你的谷歌联系人:

http://github.com/sje397/Chess

它运行于:

http://your-move.appspot.com

请注意,由于App Engine支持built-in OpenID,因此不再需要Aeoid.

相关文章

我最近重新拾起了计算机视觉,借助Python的opencv还有face_r...
说到Pooling,相信学习过CNN的朋友们都不会感到陌生。Poolin...
记得大一学Python的时候,有一个题目是判断一个数是否是复数...
文章目录 3 直方图Histogramplot1. 基本直方图的绘制 Basic ...
文章目录 5 小提琴图Violinplot1. 基础小提琴图绘制 Basic v...
文章目录 4 核密度图Densityplot1. 基础核密度图绘制 Basic ...