我想使用python和驗證網站api(v1)在我的網站管理員工具中驗證網站。在這個例子中,我想使用驗證API獲取所有已驗證的站點,因爲該函數沒有參數。 (我知道,它通過網站管理員工具是可能的,也是)權限不足網站驗證Google
#!/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
)
任何想法我做錯了或如何調試代碼?
我要驗證網站,但問題是,我的API實現不起作用。因爲'list'沒有參數,所以我先試了一個。希望你瞭解我的問題。謝謝你的幫助。 – Wikunia 2015-02-07 16:22:33
除「無效」之外,沒有人瞭解您的問題。這不足以幫助您詳細說明。您應該編輯您的問題,並提供一個我們可以認真查看的最小工作示例!首先用您實際導入的內容替換「#some import statements ...」。 – 2015-02-07 16:27:41
對不起,我已經提供了一個完整的代碼示例。 – Wikunia 2015-02-07 16:36:29