AuthSub:(404,'未找到','未知用户'。)

时间:2011-10-14 10:50:00

标签: python django gdata authsub

我尝试将Picasa API与AuthSub一起使用。我的代码:

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收到错误:

  

(404,'未找到','未知用户'。)

     

回溯:   在get_response中输入文件“/home/i159/Envs/photorulez/lib/python2.6/site-packages/django/core/handlers/base.py”     111. response = callback(request,* callback_args,** callback_kwargs)   在add_album中输入文件“/home/i159/workspace/photorulez/photorulez/photoapp/views.py”     49. GD_CLIENT.InsertAlbum(title = title,summary = summary)   在InsertAlbum中输入文件“/home/i159/Envs/photorulez/lib/python2.6/site-packages/gdata/photos/service.py”     358.提出GooglePhotosException(e.args [0])

     

异常类型:/ add_album /的GooglePhotosException   例外值:(404,'未找到','未知用户'。)

为什么会被提出?需要做哪些改变?

2 个答案:

答案 0 :(得分: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')

答案 1 :(得分:0)

这是我的功能,用于验证我有会话令牌的用户:

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

    gd_client.SetAuthSubToken(authsub_token)

    return gd_client

如果您将电子邮件或用户名设为“默认”,他将使用授权令牌的用户