Django-social-auth 谷歌 oauth 令牌使用
我正在使用 Django-socila-auth 插件。它使用 google 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 feed URL,作为社交身份验证请求权限的选项字符串,因此在使用 google 授权时,我的令牌会请求 Picassa feed 权限。
顺便提一句。我使用过的 Google 教程是:此处 我知道它是 Oauth 1.0 而不是 AusSub,但问题是:
如何使用我拥有的令牌和秘密进行身份验证并使用此权限发布照片?
I'm using Django-socila-auth plugin. It uses google API for Oauth 1.0 Authentication. Question is have anybody used it with google python API (gdata). I mean how to apply auth session_token, stored in django-social-auth model to my api call.
Can you help me with code to get this token from model and apply to gdata.PhotoService() instance. For now it is like this:
#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')
I'm recieving error
403 Invalid token string.
I understand that it needs secret too but how to apply it to API for auth?(To receive authorization to post photos.). BTW I added Picassa feed URL, as an option string for social-auth to ask permissions, so token I have asks for Picassa feed permissions when authorizing with google.
BTW. Google tutorial I've used is: here
I understand it's Oauth 1.0 rather than AusSub, but question is:
how to authenticate with token and secret I have and post a photo with this permission?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是为了回答我自己的问题。我使用了错误的方法来做到这一点,因为“gd_client”和 AuthSub 出现问题。
它必须检查服务器上的令牌。它不能在本地主机上执行此操作。您需要展望 Oauth/Oauth2 以获得更好的调试等等...尽管它比 AuthSub 复杂得多
Just to answer my own problem. I used wrong way to do it, because problem in 'gd_client' and AuthSub.
It must check token on server. And it can not do it on localhost. You need to look ahead to Oauth/Oauth2 for better debugging and so on... No matter that it is much complex than AuthSub