0

我尝试将 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 111 中的文件“/home/i159/Envs/photorulez/lib/python2.6/site-packages/django/core/handlers/base.py”。response = callback(request, *callback_args, **callback_kwargs) add_album 49 中的文件“/home/i159/workspace/photorulez/photorulez/photoapp/views.py”。 GD_CLIENT.InsertAlbum(title=title, summary=summary) 文件“/home/i159/Envs/photorulez/lib/python2. 6/site-packages/gdata/photos/service.py”在 InsertAlbum 358 中。引发 GooglePhotosException(e.args[0])

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

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

4

2 回答 2

0

我得到了它!!!GD_CLIENT = gdata.photos.service.PhotosService() 需要email关键字参数作为 Google 帐户用户名。

gdata.photos.service.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')
于 2011-10-14T11:41:42.050 回答
0

这是我对拥有会话令牌的用户进行身份验证的功能:

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

    gd_client.SetAuthSubToken(authsub_token)

    return gd_client

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

于 2012-01-20T20:00:19.943 回答