I'm writing a Python script to submit sitemaps in a row to the Search Console. Python quickstart example is working OK : https://developers.google.com/webmaster-tools/search-console-api-original/v3/quickstart/quickstart-python
I tried with the following code to submit my sitemaps:
CLIENT_ID = 'xxxxx'
CLIENT_SECRET = 'yyyyyy'
OAUTH_SCOPE = 'https://www.googleapis.com/auth/webmasters'
# Redirect URI for installed apps
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'
# Run through the OAuth flow and retrieve credentials
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI)
authorize_url = flow.step1_get_authorize_url()
print ('Go to the following link in your browser: ' + authorize_url)
code = input('Enter verification code: ').strip()
credentials = flow.step2_exchange(code)
# Create an httplib2.Http object and authorize it with our credentials
http = httplib2.Http()
http = credentials.authorize(http)
webmasters_service = build('webmasters', 'v3', http=http)
WEBSITE = 'http://www.mywebsite.com'
SITEMAP_PATH = 'http://www.mywebsite.com/sitemaps/'
SITEMAPS_LIST = ['sitemap1.xml','sitemap2.xml','sitemap3.xml']
print ('Adding sitemaps to website ' + WEBSITE)
for sitemap in SITEMAPS_LIST:
print (' '+SITEMAP_PATH + sitemap)
webmasters_service.sitemaps().submit(siteUrl=WEBSITE, feedpath=SITEMAP_PATH + sitemap)
No error. But the sitemaps are not added to my Search Console. If I try to add a file manually in Search Console or through the API explorer web interface, it's working.