SearchConsoleAPIのクイックスタートを触っていますが、
認証周りでエラーが返ってきて、
どの部分を調査すればよいのか見当がつかなく、困っている状態です。
アドバイスをいただけないでしょうか。。
実行コード:
python
1#!/usr/bin/python 2 3import httplib2 4 5from apiclient import errors 6from apiclient.discovery import build 7from oauth2client.client import OAuth2WebServerFlow 8 9 10# Copy your credentials from the console 11CLIENT_ID = 'YOUR_CLIENT_ID' 12CLIENT_SECRET = 'YOUR_CLIENT_SECRET' 13 14# Check https://developers.google.com/webmaster-tools/search-console-api-original/v3/ for all available scopes 15OAUTH_SCOPE = 'https://www.googleapis.com/auth/webmasters.readonly' 16 17# Redirect URI for installed apps 18REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob' 19 20# Run through the OAuth flow and retrieve credentials 21flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI) 22authorize_url = flow.step1_get_authorize_url() 23print 'Go to the following link in your browser: ' + authorize_url 24code = raw_input('Enter verification code: ').strip() 25credentials = flow.step2_exchange(code) 26 27# Create an httplib2.Http object and authorize it with our credentials 28http = httplib2.Http() 29http = credentials.authorize(http) 30 31webmasters_service = build('webmasters', 'v3', http=http) 32 33# Retrieve list of properties in account 34site_list = webmasters_service.sites().list().execute() 35 36# Filter for verified websites 37verified_sites_urls = [s['siteUrl'] for s in site_list['siteEntry'] 38 if s['permissionLevel'] != 'siteUnverifiedUser' 39 and s['siteUrl'][:4] == 'http'] 40 41# Printing the URLs of all websites you are verified for. 42for site_url in verified_sites_urls: 43 print site_url 44 # Retrieve list of sitemaps submitted 45 sitemaps = webmasters_service.sitemaps().list(siteUrl=site_url).execute() 46 if 'sitemap' in sitemaps: 47 sitemap_urls = [s['path'] for s in sitemaps['sitemap']] 48 print " " + "\n ".join(sitemap_urls) 49
実行内容:
iterm2
1$ python webmasters-quickstart.py
エラー文:
iterm2
1__init__() takes at most 4 positional arguments (5 given) 2Go to the following link in your browser: https://accounts.google.com/o/oauth2/v2/auth?client_id=(以下略) 3Enter verification code: (以下略) 4Traceback (most recent call last): 5 File "webmasters-quickstart.py", line 25, in <module> 6 credentials = flow.step2_exchange(code) 7 File "/anaconda3/lib/python3.7/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper 8 return wrapped(*args, **kwargs) 9 File "/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 2089, in step2_exchange 10 raise FlowExchangeError(error_msg) 11oauth2client.client.FlowExchangeError: invalid_clientUnauthorized
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。