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

发布于 2024-12-10 04:24:35 字数 1719 浏览 5 评论 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 中的文件“/home/i159/Envs/photorulez/lib/python2.6/site-packages/django/core/handlers/base.py” 111. 响应 = 回调(请求,*callback_args,**callback_kwargs) add_album 中的文件“/home/i159/workspace/photorulez/photorulez/photoapp/views.py” 49. GD_CLIENT.InsertAlbum(标题=标题,摘要=摘要) InsertAlbum 中的文件“/home/i159/Envs/photorulez/lib/python2.6/site-packages/gdata/photos/service.py” 358. 引发 GooglePhotosException(e.args[0])

异常类型:GooglePhotosException at /add_album/ 异常值:(404,“未找到”,“未知用户。”)

为什么会引发该异常?需要做出哪些改变?

I try to use Picasa API with AuthSub. My code:

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})

I got an error at add_album:

(404, 'Not Found', 'Unknown user.')

Traceback:
File "/home/i159/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
49. GD_CLIENT.InsertAlbum(title=title, summary=summary)
File "/home/i159/Envs/photorulez/lib/python2.6/site-packages/gdata/photos/service.py" in InsertAlbum
358. raise GooglePhotosException(e.args[0])

Exception Type: GooglePhotosException at /add_album/
Exception Value: (404, 'Not Found', 'Unknown user.')

Why is it raised? What changes are needed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙沙粒小 2024-12-17 04:24:35

我得到了它!!! 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')

I got it!!! GD_CLIENT = gdata.photos.service.PhotosService() needed email keyword argument as Google account user name.

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):

So it should be:

GD_CLIENT = gdata.photos.service.PhotosService(email='username')
柏林苍穹下 2024-12-17 04:24:35

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

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

    gd_client.SetAuthSubToken(authsub_token)

    return gd_client

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

This is my function to authenticate a user that i have a session token:

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

    gd_client.SetAuthSubToken(authsub_token)

    return gd_client

If you put the email, or username as 'default' he will use the user that authorized the token

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文