Google Search Console。不是有效的Search Console网站网址

时间:2018-07-05 13:47:41

标签: python python-3.x google-search-console

我正在尝试获取针对我的网站的搜索查询。

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。“>

我不明白怎么了。

在信息中心中,我的网址与输入的网址完全相同: enter image description here

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

按如下所示正确运行程序:

python googleapisearch.py 'http://enquetemaken.be/' '2018-06-12' '2018-06-13'