【问题标题】:Django-social-auth google oauth token usageDjango-social-auth google oauth 令牌使用
【发布时间】:2011-08-19 11:16:10
【问题描述】:

我正在使用Django-socila-auth plugin。它使用 google API 进行 Oauth 1.0 身份验证。问题是有人将它与谷歌python API(gdata)一起使用。我的意思是如何将存储在 django-social-auth 模型中的 auth session_token 应用到我的 api 调用中。

您能否帮我编写代码以从模型中获取此令牌并应用于 gdata.PhotoService() 实例。现在是这样的:

        #getting model instance from django-social-auth model
        association = Association.objects.get(user=request.user)
        
        google_session_token=association.handle
        google_secret=association.secret
        
        #token string from django-social-auth 
        #model Association field "handle" looks like:
        #google_session_token = '.......XG84PjwytqJkvr8WQhDxm1w-JplWK5zPndSHB13f.........'
        
        gd_client = gdata.photos.service.PhotosService()
        gd_client.debug = 'true'
        gd_client.auth_token = google_session_token
        #image.image is a file field, but problem not in this.
        #it tries to send file in debug text. 
        #It just recieves 403 unauthorised callback.
        photo = gd_client.InsertPhotoSimple(
            '/data/feed/api/user/default/albumid/default', 'New Photo', 
            'Uploaded using the API', image.image, content_type='image/jpeg')

我收到错误消息

403 Invalid token string.

我知道它也需要秘密,但如何将其应用于 API 进行身份验证?(获得发布照片的授权。)。顺便说一句,我添加了 Picassa 提要 URL,作为社交身份验证请求权限的选项字符串,因此我在向 google 授权时要求提供 Picassa 提要权限。

顺便说一句。我用过的谷歌教程是:here 我知道它是 Oauth 1.0 而不是 AusSub,但问题是:

如何使用我拥有的令牌和秘密进行身份验证并发布具有此权限的照片?

【问题讨论】:

  • 遇到了类似的问题,但使用的是 Google 日历。我只是无法让我的代码正确使用令牌。你有没有办法让它工作?

标签: django google-api picasa django-socialauth


【解决方案1】:

只是为了回答我自己的问题。我使用了错误的方法,因为“gd_client”和 AuthSub 中的问题。 它必须检查服务器上的令牌。它不能在本地主机上做到这一点。您需要展望 Oauth/Oauth2 以获得更好的调试等等......不管它比 AuthSub 复杂得多

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 2018-07-18
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    • 2012-10-06
    相关资源
    最近更新 更多