Google Data API - 尝试通过 Upgradetosessiontoken 将 authsub_token 交换为 session_token 会导致“NonAuthSubToken”

发布于 2024-11-18 05:15:53 字数 1557 浏览 3 评论 0 原文

我完全使用此处示例中的代码:http: //code.google.com/apis/picasaweb/docs/1.0/developers_guide_python.html#Auth

仍然没有骰子。

这是我得到的确切代码(这一切都在网络服务器上运行):

#!/usr/bin/python

import gdata.photos.service
import gdata.media
import gdata.geo

print "content-type:text/html\n"

def GetAuthSubUrl():
  next = 'http://my_domain.com/foo/connect_picasa.cgi'
  scope = 'http://picasaweb.google.com/data/'
  secure = False
  session = True
  gd_client = gdata.photos.service.PhotosService()
  return gd_client.GenerateAuthSubURL(next, scope, secure, session);

authSubUrl = GetAuthSubUrl();
print '<a href="%s">Login to your Google account</a>' % authSubUrl

然后在 my_domain/foo/connect_picasa.cgi 我有:

#!/usr/bin/python

import gdata.photos.service
import gdata.media
import gdata.geo
import cgi

parameters = cgi.FieldStorage()
authsub_token = parameters['token']

print "content-type:text/html\n"

#debugging
print authsub_token

gd_client = gdata.photos.service.PhotosService()
gd_client.auth_token = authsub_token
gd_client.UpgradeToSessionToken()

#more debugging
print "BLINKENLICHTEN"

它在 gd_client.UpgradeToSessionToken 中退出() 与: raise NonAuthSubToken

也许我在这里遗漏了一些明显的东西?执行 parameters['token']parameters['token'].value [这对我来说似乎更明显]会导致同样的结果。将 authsub_token 设置为“tacos”也会导致相同的错误,使我相信我的 authsub_token 根本无效。

I'm using exactly the code in the examples from here: http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_python.html#Auth

Still no dice.

Here is the exact code I've got (this is all running on a web server):

#!/usr/bin/python

import gdata.photos.service
import gdata.media
import gdata.geo

print "content-type:text/html\n"

def GetAuthSubUrl():
  next = 'http://my_domain.com/foo/connect_picasa.cgi'
  scope = 'http://picasaweb.google.com/data/'
  secure = False
  session = True
  gd_client = gdata.photos.service.PhotosService()
  return gd_client.GenerateAuthSubURL(next, scope, secure, session);

authSubUrl = GetAuthSubUrl();
print '<a href="%s">Login to your Google account</a>' % authSubUrl

And then at my_domain/foo/connect_picasa.cgi I have:

#!/usr/bin/python

import gdata.photos.service
import gdata.media
import gdata.geo
import cgi

parameters = cgi.FieldStorage()
authsub_token = parameters['token']

print "content-type:text/html\n"

#debugging
print authsub_token

gd_client = gdata.photos.service.PhotosService()
gd_client.auth_token = authsub_token
gd_client.UpgradeToSessionToken()

#more debugging
print "BLINKENLICHTEN"

It's bailing out at gd_client.UpgradeToSessionToken() with: raise NonAuthSubToken

Maybe I'm missing something obvious here? Doing parameters['token'] and parameters['token'].value [which seems more obvious to me] result in the same thing. Setting the authsub_token to "tacos", also results in the same error, leading me to believe that my authsub_token in simply invalid.

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

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

发布评论

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

评论(1

快乐很简单 2024-11-25 05:15:53

我正在回答我自己的问题,以便其他人可以从中受益:

谷歌文档已过时。在这里找到了答案:http://www. mail-archive.com/[电子邮件受保护]/msg09180.html

代码应该是这样的:

确实需要实际值。所以要么给它一个.value,要么使用parameters.getvalue("token")

authsub_token = parameters['token'].value
print "content-type:text/html\n"

gd_client = gdata.photos.service.PhotosService()

这是重要的部分。使用 gd_client.SetAUthSubToken,而不是 gd_client.authsubtoken =

gd_client.SetAuthSubToken(authsub_token) 
gd_client.UpgradeToSessionToken()

希望这可以帮助其他人。这真是一个令人头疼的事。

I'm answering my own question so that others can benefit from it:

The google documentation is out of date. Found the answer here: http://www.mail-archive.com/[email protected]/msg09180.html

This is what the code should look like:

It does need the actual value. So either give it a .value, or use parameters.getvalue("token")

authsub_token = parameters['token'].value
print "content-type:text/html\n"

gd_client = gdata.photos.service.PhotosService()

This is the important part. Use gd_client.SetAUthSubToken, not gd_client.authsubtoken =

gd_client.SetAuthSubToken(authsub_token) 
gd_client.UpgradeToSessionToken()

Hope this helps anybody else out. This was a real headbanger.

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