Django-social-auth谷歌oauth令牌使用

时间:2011-08-19 11:16:10

标签: django google-api picasa django-socialauth

我正在使用Django-socila-auth plugin。它使用谷歌API进行Oauth 1.0身份验证。问题是任何人都使用google 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提要权限。

顺便说一句。我用过的Google教程是:here 我理解它是Oauth 1.0而不是AusSub,但问题是:

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

1 个答案:

答案 0 :(得分:0)

回答我自己的问题。我用错误的方法来做,因为'gd_client'和AuthSub中的问题。 它必须检查服务器上的令牌。它无法在localhost上执行。您需要向前看Oauth / Oauth2以获得更好的调试等等......不管它是否比AuthSub复杂