2011-10-14 32 views
0

我嘗試在AuthSub中使用Picasa API。我的代碼:AuthSub:(404,'未找到','未知用戶')

(404, '未找到', '未知的用戶'。)

回溯: 文件「/家/ i159

GD_CLIENT = gdata.photos.service.PhotosService() 

def login(request): 
    def GetAuthSubUrl(): 
     callback = 'http://127.0.0.1:8000/callback' 
     scope = 'https://picasaweb.google.com/data/' 
     secure = False 
     session = True 
     return GD_CLIENT.GenerateAuthSubURL(callback, scope, secure, session) 

    auth_sub_url = GetAuthSubUrl() 
    return HttpResponseRedirect(auth_sub_url) 


def confirm(request): 
    authsub_token = request.GET['token']  
    token = GD_CLIENT.SetAuthSubToken(authsub_token) 
    GD_CLIENT.UpgradeToSessionToken() 
    GD_CLIENT.auth_token = token 
    return direct_to_template(request, 'base.djhtml') 


def add_album(request): 
    form = AddAlbum(request.POST or None) 
    if form.is_valid(): 
     data = form.cleaned_data 
     title = data.get('title') 
     summary = data.get('summary') 
     GD_CLIENT.InsertAlbum(title=title, summary=summary) 
     return HttpResponseRedirect('/get_albums/') 
    return render(request, 'add_form.djhtml', {'form': form}) 

我在add_album得到一個錯誤/Envs/photorulez/lib/python2.6/site-packages/django/core/handlers/base.py「in get_response 111. response = callback(request,* callback_args,** callback_kwargs) File」/ home/i159 /workspace/photorulez/photorulez/photoapp/views.py「in add_album 4 9. GD_CLIENT.InsertAlbum(title = title,summary = summary) InsertAlbum中的文件「/home/i159/Envs/photorulez/lib/python2.6/site-packages/gdata/photos/service.py」 358. raise在/ add_album/ 異常值GooglePhotosException:GooglePhotosException(e.args [0])

異常類型(404, '未找到', '未知用戶')

爲什麼它提出?需要進行哪些更改?

回答

0

我明白了! GD_CLIENT = gdata.photos.service.PhotosService()需要email作爲Google帳戶用戶名的關鍵字參數。

gdata.photos.sevice.py

class PhotosService(gdata.service.GDataService): 
    ssl = True 
    userUri = '/data/feed/api/user/%s' 

    def __init__(self, email=None, password=None, source=None, 
      server='picasaweb.google.com', additional_headers=None, 
      **kwargs): 

所以它應該是:

GD_CLIENT = gdata.photos.service.PhotosService(email='username') 
+0

你可以接受你的答案是正確的 - 點擊左邊的綠色框 –

+0

僅兩天後。 – I159

0

這是我的功能,我有一個會話令牌驗證用戶的身份:

def get_client(authsub_token): 
    gd_client = gdata.photos.service.PhotosService(email='default') 

    gd_client.SetAuthSubToken(authsub_token) 

    return gd_client 

如果您將電子郵件或用戶名設置爲「默認」,他將使用授權令牌的用戶