1

Google Webマスターツール(Search Console)用のサーバーtoサーバーアプリケーション用にOAuth 2.0を使用しようとしていますので、手順はhereです。OAuth 2.0サーバーからサーバーへの資格情報の認証失敗(Search Console - ウェブマスターツール)

このアプリケーションは、Google App EngineまたはGoogle Compute Engine

サービスアカウントを作成し、ドメイン全体の委任を有効にありません。 .jsonファイルをダウンロードし、スクリプトのルートに保存しました。

サンプル:

from oauth2client.service_account import ServiceAccountCredentials 
from apiclient.discovery import build 
from httplib2 import Http  

scopes = ['https://www.googleapis.com/auth/webmasters.readonly'] 

credentials = ServiceAccountCredentials.from_json_keyfile_name(
     'keyfile.json', scopes=scopes) 

http_auth = credentials.authorize(Http()) 

webmasters_service = build('webmasters', 'v3', http=http_auth) 

site_list = webmasters_service.sites().list().execute() 
print(site_list) 

しかし、私は

{}空のデータセットを取得しています。 keyfile.jsonのメールアドレスを変更した場合でもこれは、ファイルが何らかの形で使用されていないことを示しています。したがって、アカウント内のサイトのリストを空にすることを試みます。

私は

site_list = webmasters_service.sitemaps().list(siteUrl="www.example.com").execute() 

をすれば私が手:

再びそれは持っていないため、このアカウントは与えられたURLのサイトマップを取得する権利はない、と言われます
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/webmasters/v3/sites/www.example.com/sitemaps?alt=json returned "User does not have sufficient permission for site 'http://www.example.com/'. See also: https://support.google.com/webmasters/answer/2451999."> 

適切なアクセス許可。

このアカウントはオーナーアカウントで、service accountには所有者権限があります。

すべてのアイデア?

は、私は自分の質問に答えることを憎むが、ここで私はそれが動作するように作られた方法である

答えて

1

ありがとう。

だから、一番下の行は

に、あります...チュートリアル誰かが、新しく生成された電子メールアドレスをアプリケーションの許可のセクションに追加することについて言及するのを忘れた...

+0

'oauth2client'のどのバージョンを使用していますか?私は 'oauth2client.service_account import ServiceAccountCredentials'を試みましたが、' ServiceAccountCredentials'が私のバージョンの 'oauth2client.service_account'に含まれているようには見えません。私は 'ServiceAccountCredentials'クラスを参照しています... – Abundnce10

+0

私は' google-api-python-client(1.5.0) 'を使っています。これは 'pip install --upgrade google-api-python-client'でバージョンが提供されています。それが役に立てば幸い。 [Doc](https://developers.google.com/webmaster-tools/v3/quickstart/quickstart-python#step_1_enable_the_search_console_api) – Leustad

+0

私はもともと 'pip install --upgrade oauth2client'を実行しましたが、私は以前のバージョンの' pip 'それは適切にアップグレードされません。私は 'pip'で最新で、' oauth2client'は 'ServiceAccountCredentials'クラスを持っています。ありがとう! – Abundnce10

関連する問題