質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

Q&A

1回答

492閲覧

[python]SearchConsoleAPIのクイックスタート

cultiva

総合スコア19

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

0グッド

0クリップ

投稿2019/02/23 07:49

SearchConsoleAPIのクイックスタートを触っていますが、
認証周りでエラーが返ってきて、
どの部分を調査すればよいのか見当がつかなく、困っている状態です。

アドバイスをいただけないでしょうか。。

参考URL:
https://developers.google.com/webmaster-tools/search-console-api-original/v3/quickstart/quickstart-python

実行コード:

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

python

1# Copy your credentials from the console 2CLIENT_ID = 'YOUR_CLIENT_ID' 3CLIENT_SECRET = 'YOUR_CLIENT_SECRET'

の部分はちゃんと「Step 1: Enable the Search Console API」で取得したものに書き換えていますか?

認証に失敗しているということなので、その辺でなにかミスっている可能性しかなさそうですが・・・

投稿2019/02/23 10:57

hayataka2049

総合スコア30933

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問