【问题标题】:Developing OAuth for Google apps engine ...Python为 Google 应用引擎开发 OAuth ...Python
【发布时间】:2011-09-04 20:14:36
【问题描述】:
RequestError: Unable to upgrade OAuth request token to access token: 400, signature_invalid

base_string:POST&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetAccessToken&oauth_consumer_key%3Dcalendar-auth.appspot.com%26oauth_nonce%3D646112512717164%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1306760936%26oauth_token%3D4%252F-cP-Ai1NzxDtLehvtzRbGd4SHZ1-%26oauth_verifier%3DPYGMYX8riH9AfpJvTEh_Ztzm%26oauth_version%3D1.0

我是谷歌应用程序开发的新手。正在尝试在 Web 应用程序中实现 OAuth。当我调用 GetAccessToken() 方法时,它会显示上述错误。请帮我解决这个问题.... 我正在使用以下代码...:

class MainHandler(webapp.RequestHandler):
    def get(self):
        CONSUMER_KEY = 'xyz'
        CONSUMER_SECRET = 'xyz'
        SCOPES = ['https://docs.google.com/feeds/', 'https://www.google.com/calendar/feeds/']  # example of a multi-scoped token

        client = gdata.docs.client.DocsClient(source='xyz')

        oauth_callback_url = 'http://%s/get_access_token' % self.request.host
        request_token = client.GetOAuthToken(
            SCOPES, oauth_callback_url, CONSUMER_KEY, consumer_secret=CONSUMER_SECRET)
        memcache.add("rtoken",request_token,3600)
        domain = 'default'  # If on a Google Apps domain, use your domain (e.g. 'example.com').
        url = str(request_token.generate_authorization_url(google_apps_domain=domain))
        self.redirect(url)

class AuthToken(webapp.RequestHandler):
    def get(self):
        client = gdata.docs.client.DocsClient(source='xyz')
        saved_request_token = memcache.get("rtoken")        
        request_token = gdata.gauth.AuthorizeRequestToken(saved_request_token, self.request.uri)
        self.response.out.write("Got the token")
        access_token = client.GetAccessToken(request_token)

【问题讨论】:

    标签: python google-app-engine oauth


    【解决方案1】:
    https://www.google.com/accounts/OAuthGetAccessToken
    {
    oauth_consumer_key=calendar-auth.appspot.com
    oauth_nonce=646112512717164
    oauth_signature_method=HMAC-SHA1
    oauth_timestamp=1306760936
    oauth_token=4/-cP-Ai1NzxDtLehvtzRbGd4SHZ1-
    oauth_verifier=PYGMYX8riH9AfpJvTEh_Ztzm
    oauth_version=1.0
    }
    

    我建议不要向公众发布 oauth 令牌。

    根据http://wiki.oauth.net/w/page/12238555/Signed-Callback-URLs,您应该发布 oauth_signature,但我没有在列表中看到它

    【讨论】:

    • 是的,对不起我的错误..我会处理这个下一次..谢谢您的回答...但我不知道如何提供 oauth_signature 参数...我正在打电话google apis,并将我的消费者密钥和秘密作为参数发送......我认为google apis将生成oauth_signature......你能通过查看我的代码来帮助我解决这个问题......如何在请求中发布那个oauth_signature。 .. :)
    猜你喜欢
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    相关资源
    最近更新 更多