2011-08-19 28 views
0

我正在使用Django-socila-auth plugin。它使用Google API for Oauth 1.0身份驗證。問題是有人用它與谷歌python API(gdata)。我的意思是如何將auth session_token應用於django-social-auth模型中並存儲到我的api調用中。Django-social-auth google oauth令牌使用情況

你能幫我用代碼從模型中獲取這個令牌並應用到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') 

我recieving錯誤

403 Invalid token string. 

我明白,這需要祕密太多,但如何將其應用到API是面向auth(要獲得授權發佈照片? )。順便說一句,我添加了Picassa feed url,作爲social-auth的一個選項字符串來詢問權限,因此我在使用google授權時要求提供Picassa feed權限。

順便說一句。谷歌教程中我使用的是:here 我理解的OAuth 1.0,而不是AusSub,但問題是:

如何使用令牌和祕密我已經和張貼擁有此權限的照片進行身份驗證?

+0

有類似的問題,但使用Google日曆。我只是無法讓我的代碼正確使用令牌。你有沒有找到一種方法來使這個工作? – Kai

回答

0

只是爲了回答我自己的問題。我用錯誤的方式來做到這一點,因爲'gd_client'和AuthSub中存在問題。 它必須檢查服務器上的令牌。而且它不能在本地主機上完成。您需要展望Oauth/Oauth2以進行更好的調試等等......無論它是否比AuthSub更復雜

相關問題