我想在我的站长工具中使用python和验证站点api (v1)来验证网站。在本例中,我希望使用验证api获得所有经过验证的站点,因为该函数没有参数。(我知道这也可以通过网站管理员工具来实现)
#!/usr/bin/python
import httplib2
from apiclient import errors
from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.file import Storage
http = httplib2.Http()
storage = Storage('credentials')
storage_verify = Storage('credentials_verify')
credentials = storage.get()
credentials_verify = storage_verify.get()
http_wm = credentials.authorize(http)
http_sv = credentials_verify.authorize(http)
webmasters_service = build('webmasters', 'v3', http=http_wm)
verification_service = build('siteVerification', 'v1', http=http_sv)
site_list = webmasters_service.sites().list().execute()
print(site_list)
# this line generates the error
verified_site_list = verification_service.webResource().list().execute()
print(verified_site_list)权限不足错误:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/siteVerification/v1/webResource?alt=json returned "Insufficient Permission">我拥有对siteVerification api的读写访问权限(我已经在这里检查了我的令牌:https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=TOKEN )
你知道我做错了什么吗?或者我该如何调试代码?
发布于 2015-02-08 00:18:45
确保您完整地阅读和理解了https://developers.google.com/site-verification/v1/invoking。尤其需要注意的是:
验证新站点
要验证站点,
验证该站点是否为您的站点
您所需要做的就是正确地构造两个请求:getToken和insert。我在上面链接的文档中详细讨论了“正确”是什么意思。
如果你真的需要代码方面的帮助,你需要展示一个最小的工作示例,这样我们就可以重现你检索到的错误。
发布于 2015-02-08 20:03:58
我找到了我的问题..。
这两行代码:
http_wm = credentials.authorize(http)
http_sv = credentials_verify.authorize(http)使用相同的http对象,这是不允许的。
我现在使用以下代码:
http_wm = httplib2.Http()
http_sv = httplib2.Http()
http_wm = credentials.authorize(http_wm)
http_sv = credentials_verify.authorize(http_sv)https://stackoverflow.com/questions/28382850
复制相似问题