简体   繁体   中英

Google Search Console API - Domain Wide Delegation - Returning no results

I setup (are at least attempted to) a domain-wide delegation for our Google apps domain for integration with a python script. In particular, I am currently trying to interact with the Search Console API.

Here is what I have done:

  1. Setup service account
  2. Enabled domain wide delegation
  3. Added https://www.googleapis.com/auth/webmasters.readonly to the Google Admin console for the Authorized API client list.
  4. Setup a simple script based off the one provided by Google

Here is my test.py script:

#!/usr/bin/python

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


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

credentials = ServiceAccountCredentials.from_json_keyfile_name('/path/to/my/key.json', scopes)
delegated_credentials = credentials.create_delegated('me@mydomain.com')

http_auth = credentials.authorize(Http())

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

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

print site_list

The result:

{}

Bummer.

I know that this is incorrect because when I use API Explorer and authorize me@mydomain.com I see the full list of my sites in Search Console. Something is broken, and I am not sure where the problem is.

Any thoughts on steps that I missed in the process? Everything seems to authenticate. I do not get a 403 .

Scratching my head.

So I am not 100% sure what I did, or how I fixed it.

I was playing around with the permissions in the Admin console API client access utility with having and not having a trailing / . In the end, I changed my scope from https://www.googleapis.com/auth/webmasters.readonly to https://www.googleapis.com/auth/webmasters and it worked!

I have not yet gone back to play with the readonly scope, partially because I do want my program to have write access. I was only using the readonly for test purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM