Консоль поиска Google. не является действительным URL сайта Консоли поиска - PullRequest
0 голосов
/ 05 июля 2018

Я пытаюсь получить поисковые запросы для моего сайта.

import argparse
import sys
from googleapiclient import sample_tools


def execute_request(service, property_uri, request):
    """Executes a searchAnalytics.query request.

    Args:
      service: The webmasters service to use when executing the query.
      property_uri: The site or app URI to request data for.
      request: The request to be executed.

    Returns:
      An array of response rows.
    """
    return service.searchanalytics().query(
        siteUrl=property_uri, body=request).execute()



# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('property_uri', type=str,
                       help=('Site or app URI to query data for (including '
                             'trailing slash).'))
argparser.add_argument('start_date', type=str,
                       help=('Start date of the requested date range in '
                             'YYYY-MM-DD format.'))
argparser.add_argument('end_date', type=str,
                       help=('End date of the requested date range in '
                             'YYYY-MM-DD format.'))


service, flags = sample_tools.init(
    sys.argv, 'webmasters', 'v3', __doc__, 'client_secrets.json', parents=[argparser],
    scope='https://www.googleapis.com/auth/webmasters.readonly')

# First run a query to learn which dates we have data for. You should always
# check which days in a date range have data before running your main query.
# This query shows data for the entire range, grouped and sorted by day,
# descending; any days without data will be missing from the results.
request = {
    'startDate': flags.start_date,
    'endDate': flags.end_date,
    'dimensions': ['date']
}
response = execute_request(service, flags.property_uri, request)
print(response)

Когда я запускаю программу:

python googleapisearch.py property_uri=http://enquetemaken.be/ start_date=2018-06-12 end_date=2018-06-13

Я получаю следующую ошибку:

googleapiclient.errors.HttpError: https://www.googleapis.com/webmasters/v3/sites/property_uri%3Dhttp%3A%2F%2Fenquetemaken.be%2F/searchAnalytics/query?alt=json возвращено "'property_uri = http://enquetemaken.be/' не является действительным Поиск URL сайта консоли. ">

Я не могу понять, что не так.

В панели инструментов мой URL-адрес точно такой же, как и при вводе: enter image description here

Что я делаю не так?

1 Ответ

0 голосов
/ 05 июля 2018

Правильно запустите программу следующим образом:

python googleapisearch.py 'http://enquetemaken.be/' '2018-06-12' '2018-06-13'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...