### Install Python Client Library Manually Source: https://developers.google.com/webmaster-tools/v1/libraries Manually install the Python client library by downloading, unpacking, and running the setup script. This method is useful if package managers are not available. ```bash python setup.py install ``` -------------------------------- ### Install Python Client Library with Setuptools Source: https://developers.google.com/webmaster-tools/v1/libraries Use easy_install to install or upgrade the google-api-python-client library. This is an alternative to pip for Python installations. ```bash easy_install --upgrade google-api-python-client ``` -------------------------------- ### Install Ruby Client Library with RubyGems Source: https://developers.google.com/webmaster-tools/v1/libraries Install the google-api-client gem using RubyGems. This command is used for initial installation of the library. ```bash gem install google-api-client ``` -------------------------------- ### Install Python Client Library with Pip Source: https://developers.google.com/webmaster-tools/v1/libraries Use pip to install or upgrade the google-api-python-client library. This is the preferred method for Python installations. ```bash pip install --upgrade google-api-python-client ``` -------------------------------- ### Example Results: Filtered by AMP_BLUE_LINK Source: https://developers.google.com/webmaster-tools/v1/how-tos/all-your-data This is an example of the results from the second query, showing a breakdown of 'AMP_BLUE_LINK' search appearance data by device type. ```json "rows": [ { "keys": [ "MOBILE" ], "clicks": 429887.0, "impressions": 1.7090783E7, "ctr": 0.025153148337323107, "position": 7.31339517914422 }, { "keys": [ "DESKTOP" ], "clicks": 0.0, "impressions": 66.0, "ctr": 0.0, "position": 12.257575757575758 }, ... ] ``` -------------------------------- ### Example Batch Request Source: https://developers.google.com/webmaster-tools/v1/how-tos/batch This example demonstrates how to construct a multipart/mixed request to batch multiple API calls. Each part represents a separate HTTP request, and the boundary separates these parts. ```http POST /batch/farm/v1 HTTP/1.1 Authorization: Bearer your_auth_token Host: www.googleapis.com Content-Type: multipart/mixed; boundary=batch_foobarbaz Content-Length: total_content_length --batch_foobarbaz Content-Type: application/http Content-ID: GET /farm/v1/animals/pony --batch_foobarbaz Content-Type: application/http Content-ID: PUT /farm/v1/animals/sheep Content-Type: application/json Content-Length: part_content_length If-Match: "etag/sheep" { "animalName": "sheep", "animalAge": "5" "peltColor": "green", } --batch_foobarbaz Content-Type: application/http Content-ID: GET /farm/v1/animals If-None-Match: "etag/animals" --batch_foobarbaz-- ``` -------------------------------- ### Example Batch Response Source: https://developers.google.com/webmaster-tools/v1/how-tos/batch This example shows the structure of a multipart/mixed response to a batch request. Each part contains the HTTP status and body for a corresponding request in the batch. ```http HTTP/1.1 200 Content-Length: response_total_content_length Content-Type: multipart/mixed; boundary=batch_foobarbaz --batch_foobarbaz Content-Type: application/http Content-ID: HTTP/1.1 200 OK Content-Type application/json Content-Length: response_part_1_content_length ETag: "etag/pony" { "kind": "farm#animal", "etag": "etag/pony", "selfLink": "/farm/v1/animals/pony", "animalName": "pony", "animalAge": 34, "peltColor": "white" } --batch_foobarbaz Content-Type: application/http Content-ID: HTTP/1.1 200 OK Content-Type: application/json Content-Length: response_part_2_content_length ETag: "etag/sheep" { "kind": "farm#animal", "etag": "etag/sheep", "selfLink": "/farm/v1/animals/sheep", "animalName": "sheep", "animalAge": 5, "peltColor": "green" } --batch_foobarbaz Content-Type: application/http Content-ID: HTTP/1.1 304 Not Modified ETag: "etag/animals" --batch_foobarbaz-- ``` -------------------------------- ### Example POST Request for URL Inspection Source: https://developers.google.com/webmaster-tools/v1/urlInspection.index/inspect Illustrates how to send a POST request to the URL Inspection API to check a URL's index status. This example uses the `webmasters` scope for authorization. ```bash curl -X POST \ 'https://searchconsole.googleapis.com/v1/urlInspection/index:inspect?key=[YOUR_API_KEY]' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \ --data-raw '{ \ "inspectionUrl": "https://example.com/page", \ "siteUrl": "https://example.com/", \ "languageCode": "en-US" \ }' ``` -------------------------------- ### Example Partial Response Body Source: https://developers.google.com/webmaster-tools/v1/how-tos/performance This is an example of a partial response body when the `fields` parameter is used successfully. Only the requested fields are included in the JSON output. ```JSON { "kind": "demo", "items": [ { "title": "First title", "characteristics": { "length": "short" } }, { "title": "Second title", "characteristics": { "length": "long" } }, ... ] } ``` -------------------------------- ### Example Results: Search Appearance Types Source: https://developers.google.com/webmaster-tools/v1/how-tos/all-your-data This is an example of the results you might receive from the first query, listing different search appearance types found on your site. ```json "rows": [ { "keys": [ "INSTANT_APP" ], "clicks": 443024.0, "impressions": 4109826.0, "ctr": 0.10779629113251997, "position": 1.088168452873674 }, { "keys": [ "AMP_BLUE_LINK" ], "clicks": 429887.0, "impressions": 1.7090884E7, "ctr": 0.025152999692701676, "position": 7.313451603790653 },... ] ``` -------------------------------- ### Get Top 10 Pages Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics Retrieves the top 10 pages based on click count. Set the start and end dates for the reporting period. ```python request = { 'startDate': flags.start_date, 'endDate': flags.end_date, 'dimensions': ['page'], 'rowLimit': 10 } ``` -------------------------------- ### Sites: get Source: https://developers.google.com/webmaster-tools/v1/sites/get Retrieves information about a specific site using its URL. The request is a `GET` method to the specified endpoint, requiring the `siteUrl` as a path parameter. The `siteUrl` can be either a URL-prefix (e.g., `http://www.example.com/`) or a domain property (e.g., `sc-domain:example.com`). Authorization is necessary, using either `webmasters.readonly` or `webmasters` scopes. No request body is needed; a successful response returns a `Sites` resource. ```APIDOC ## GET https://www.googleapis.com/webmasters/v3/sites/siteUrl ### Description Retrieves information for a specific website using its URL. ### Method GET ### Endpoint https://www.googleapis.com/webmasters/v3/sites/siteUrl ### Parameters #### Path Parameters - **siteUrl** (string) - Required - The URL of the property to retrieve, as defined by Search Console. Examples: `http://www.example.com/` (for a URL-prefix property) or `sc-domain:example.com` (for a Domain property) ### Authorization This request requires authorization with at least one of the following scopes: - `https://www.googleapis.com/auth/webmasters.readonly` - `https://www.googleapis.com/auth/webmasters` ### Request Body Do not supply a request body with this method. ### Response #### Success Response (200) - **Sites resource** - Details about the specified website. ``` -------------------------------- ### Dimension Filter Examples Source: https://developers.google.com/webmaster-tools/v1/searchanalytics/query Examples of how to define filters for dimensions within a query. These can include country, query content, or device type. ```JSON country equals FRA ``` ```JSON query contains mobile use ``` ```JSON device notContains tablet ``` -------------------------------- ### Example Search Analytics API Query for May 2015 Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics This example shows the output of a Search Analytics API query for the date range of May 1st to May 15th, 2015. It displays daily clicks, impressions, CTR, and position. ```python python search_analytics_api_sample.py 'https://www.example.com/' '2015-05-01' '2015-05-15' Available dates: Keys Clicks Impressions CTR Position 2015-05-01 22823.0 373911.0 0.0610385893969 8.1829472789 2015-05-02 16075.0 299718.0 0.0536337490574 8.14173322924 2015-05-03 18794.0 337759.0 0.055643224903 8.07772405769 2015-05-04 31894.0 468076.0 0.0681385074219 7.4104611217 2015-05-05 34392.0 482919.0 0.071216912153 7.20689805123 2015-05-06 35650.0 484353.0 0.0736033430164 7.11683214515 2015-05-07 33994.0 465812.0 0.0729779395979 6.91755472165 2015-05-08 27328.0 413007.0 0.0661683700276 7.22172747677 2015-05-09 16637.0 297302.0 0.0559599329974 8.01876206685 2015-05-10 19167.0 332607.0 0.0576265682923 7.87882696395 2015-05-11 35358.0 499888.0 0.070731843933 7.11701821208 2015-05-12 35952.0 486583.0 0.073886675038 6.80677294521 2015-05-13 34417.0 480777.0 0.071586203167 6.86552185317 2015-05-14 32029.0 457187.0 0.0700566726525 6.92575904389 2015-05-15 27071.0 415973.0 0.0650787430915 7.27105605412 ``` -------------------------------- ### Full Resource Response Example Source: https://developers.google.com/webmaster-tools/v1/how-tos/performance This JSON structure represents a full resource response, including various fields. Note that many fields are omitted for brevity. ```JSON { "kind": "demo", ... "items": [ { "title": "First title", "comment": "First comment.", "characteristics": { "length": "short", "accuracy": "high", "followers": ["Jo", "Will"], }, "status": "active", ... }, { "title": "Second title", "comment": "Second comment.", "characteristics": { "length": "long", "accuracy": "medium" "followers": [ ], }, "status": "pending", ... }, ... ] } ``` -------------------------------- ### Get Top 10 Queries Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics Retrieves the top 10 search queries based on click count. Set the start and end dates for the reporting period. ```python request = { 'startDate': flags.start_date, 'endDate': flags.end_date, 'dimensions': ['query'], 'rowLimit': 10 } ``` -------------------------------- ### Example Search Analytics API Query for June 2015 Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics This example demonstrates the output of a Search Analytics API query for the date range of June 1st to June 15th, 2015. It highlights that data may not be available for the entire specified range, as shown by the absence of data for June 15th. ```python python search_analytics_api_sample.py 'https://www.example.com/' '2015-06-01' '2015-06-15' Available dates: Keys Clicks Impressions CTR Position 2015-06-01 31897.0 468486.0 0.0680852789624 6.81207122518 2015-06-02 32975.0 460266.0 0.0716433540605 6.62655942433 2015-06-03 32779.0 459599.0 0.0713208688444 6.58126758326 2015-06-04 30116.0 435308.0 0.0691831990223 6.71409668557 2015-06-05 25188.0 380444.0 0.0662068530454 7.00998570092 2015-06-06 14829.0 272324.0 0.0544535186028 7.6309910254 2015-06-07 17896.0 318094.0 0.056260099216 7.56606223318 2015-06-08 33377.0 487274.0 0.0684973957158 6.77552260125 2015-06-09 33885.0 484241.0 0.0699754874123 6.70545451542 2015-06-10 32622.0 466250.0 0.0699667560322 6.64417372654 2015-06-11 31317.0 447306.0 0.0700124746818 6.61534832978 2015-06-12 25932.0 393791.0 0.065852190629 7.15718998149 2015-06-13 15451.0 275493.0 0.0560849095984 7.69994518917 2015-06-14 18358.0 318193.0 0.0576945438775 7.34048517724 ``` -------------------------------- ### Partial Resource Response Example Source: https://developers.google.com/webmaster-tools/v1/how-tos/performance This JSON structure represents a partial response after using the 'fields' parameter. It includes only the 'kind' and specified fields within 'items'. ```JSON { "kind": "demo", "items": [{ "title": "First title", "characteristics": { "length": "short" } }, { "title": "Second title", "characteristics": { "length": "long" } }, ... ] } ``` -------------------------------- ### GET Request to Retrieve Site Information Source: https://developers.google.com/webmaster-tools/v1/sites/get Use this GET request to fetch details about a specific website. The `siteUrl` parameter specifies the property to retrieve. ```HTTP GET https://www.googleapis.com/webmasters/v3/sites/siteUrl ``` -------------------------------- ### Sites Get Source: https://developers.google.com/webmaster-tools/v1/api_reference_index Retrieves information about a specific site. ```APIDOC ## GET /sites/siteUrl ### Description Retrieves information about a specific site. ### Method GET ### Endpoint https://www.googleapis.com/webmasters/v3/sites/siteUrl ``` -------------------------------- ### get Source: https://developers.google.com/webmaster-tools/v1/sites Retrieves detailed information about a specific site within Google Search Console. ```APIDOC ## get ### Description Retrieves information about a specific site. ### Method GET ### Endpoint /v1/sites/{siteUrl} ### Parameters #### Path Parameters - **siteUrl** (string) - Required - The URL of the property to retrieve. Examples: `http://www.example.com/` or `sc-domain:example.com` ### Response #### Success Response (200) - **siteUrl** (string) - The URL of the property. - **permissionLevel** (string) - The user's permission level for the site. Acceptable values: `siteFullUser`, `siteOwner`, `siteRestrictedUser`, `siteUnverifiedUser` ``` -------------------------------- ### HTTP GET Request for Sitemaps Source: https://developers.google.com/webmaster-tools/v1/sitemaps/get Use this GET request to retrieve information about a specific sitemap. It requires the sitemap's URL and the property's URL as registered in Search Console. ```http GET https://www.googleapis.com/webmasters/v3/sites/siteUrl/sitemaps/feedpath ``` -------------------------------- ### First Query: Get Search Appearance Types Source: https://developers.google.com/webmaster-tools/v1/how-tos/all-your-data Use this query to retrieve a list of all search appearance types available on your site. This is the first step in obtaining detailed search appearance data. ```json { "startDate": "2018-05-01", "endDate": "2018-05-31", "type": "web", "dimensions": [ "searchAppearance" ] } ``` -------------------------------- ### Sitemaps: get Source: https://developers.google.com/webmaster-tools/v1/sitemaps/get Retrieves information about a specific sitemap using its URL and the site's URL. Requires authorization and uses a GET request. ```APIDOC ## GET https://www.googleapis.com/webmasters/v3/sites/siteUrl/sitemaps/feedpath ### Description Retrieves data for a specified sitemap using its URL and the site's URL as registered in Google Search Console. ### Method GET ### Endpoint https://www.googleapis.com/webmasters/v3/sites/siteUrl/sitemaps/feedpath ### Parameters #### Path Parameters - **feedpath** (string) - Required - The URL of the actual sitemap. For example: `http://www.example.com/sitemap.xml` - **siteUrl** (string) - Required - The URL of the property as defined in Search Console. For example: `http://www.example.com/` (URL-prefix property), or `sc-domain:example.com` (Domain property). ### Authorization This request requires authorization with at least one of the following scopes: - `https://www.googleapis.com/auth/webmasters.readonly` - `https://www.googleapis.com/auth/webmasters` ### Request Body Do not supply a request body with this method. ### Response #### Success Response (200) If successful, this method returns a Sitemaps resource in the response body. ``` -------------------------------- ### GET Request to List Sitemaps Source: https://developers.google.com/webmaster-tools/v1/sitemaps/list This is the basic HTTP GET request to retrieve a list of sitemaps for a specific site. It requires the site's URL as a path parameter. You can optionally specify a sitemap index URL to filter the results. ```HTTP GET https://www.googleapis.com/webmasters/v3/sites/siteUrl/sitemaps ``` -------------------------------- ### Sitemaps Get Source: https://developers.google.com/webmaster-tools/v1/api_reference_index Retrieves information about a specific sitemap. ```APIDOC ## GET /sites/siteUrl/sitemaps/feedpath ### Description Retrieves information about a specific sitemap. ### Method GET ### Endpoint https://www.googleapis.com/webmasters/v3/sites/siteUrl/sitemaps/feedpath ``` -------------------------------- ### Request Full Resource with No Fields Parameter Source: https://developers.google.com/webmaster-tools/v1/how-tos/performance This is a basic HTTP GET request that omits the 'fields' parameter, resulting in the server returning the full resource representation. ```HTTP https://www.googleapis.com/demo/v1 ``` -------------------------------- ### GET /webmasters/v3/sites/{siteUrl}/sitemaps Source: https://developers.google.com/webmaster-tools/v1/sitemaps/list Lists the sitemaps-entries submitted for this site, or included in the sitemap index file (if `sitemapIndex` is specified in the request). ```APIDOC ## GET /webmasters/v3/sites/{siteUrl}/sitemaps ### Description Lists the sitemaps-entries submitted for this site, or included in the sitemap index file (if `sitemapIndex` is specified in the request). ### Method GET ### Endpoint https://www.googleapis.com/webmasters/v3/sites/siteUrl/sitemaps ### Parameters #### Path Parameters - **siteUrl** (string) - Required - The URL of the property as defined in Search Console. For example: `http://www.example.com/` (URL-prefix property), or `sc-domain:example.com` (Domain property). #### Query Parameters - **sitemapIndex** (string) - Optional - A URL of a site's sitemap index. For example: `http://www.example.com/sitemapindex.xml` ### Authorization Requires authorization with at least one of the following scopes: - `https://www.googleapis.com/auth/webmasters.readonly` - `https://www.googleapis.com/auth/webmasters` ### Request Body Do not supply a request body with this method. ### Response #### Success Response (200) { "sitemap": [ sitemaps Resource ] } - **sitemap[]** (list) - Contains detailed information about a specific URL submitted as a sitemap. ``` -------------------------------- ### Get First 25,000 Mobile Queries Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics Retrieve the first 25,000 mobile search queries for a given date range. This is the maximum number of rows that can be retrieved in a single request. ```python request = { 'startDate': flags.start_date, 'endDate': flags.end_date, 'dimensions': ['query'], 'dimensionFilterGroups': [{ 'filters': [{ 'dimension': 'device', 'expression': 'mobile' }] }], 'rowLimit': 25000, 'startRow': 0 } ``` -------------------------------- ### Verify Data Presence with Search Analytics API Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics Use this snippet to construct a request to check for the presence of data within a given time range. It requires setting the start date, end date, and specifying 'date' as the only dimension. ```python request = { 'startDate': flags.start_date, 'endDate': flags.end_date, 'dimensions': ['date'] } ``` -------------------------------- ### Get Next 10 Mobile Queries (Rows 11-20) Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics Retrieve the next 10 mobile search queries (rows 11-20) for a given date range. This is useful for paginating results and fetching data in chunks. ```python request = { 'startDate': flags.start_date, 'endDate': flags.end_date, 'dimensions': ['query'], 'dimensionFilterGroups': [{ 'filters': [{ 'dimension': 'device', 'expression': 'mobile' }] }], 'rowLimit': 10, 'startRow': 10 } ``` -------------------------------- ### Example Global API Error Response Source: https://developers.google.com/webmaster-tools/v1/errors This JSON structure demonstrates how a global error is communicated by Google APIs, including details like domain, reason, message, and HTTP code. ```json { "error": { "errors": [ { "domain": "**global**", "reason": "invalidParameter", "message": "Invalid string value: 'asdf'. Allowed values: [mostpopular]", "locationType": "parameter", "location": "chart" } ], "code": 400, "message": "Invalid string value: 'asdf'. Allowed values: [mostpopular]" } } ``` -------------------------------- ### Request Partial Resource with Fields Parameter Source: https://developers.google.com/webmaster-tools/v1/how-tos/performance This HTTP GET request uses the 'fields' parameter to specify that only 'kind' and 'items(title,characteristics/length)' should be returned, significantly reducing the response size. ```HTTP https://www.googleapis.com/demo/v1?**fields=kind,items(title,characteristics/length)** ``` -------------------------------- ### Get Next 25,000 Mobile Queries (Rows 25,001-50,000) Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics Retrieve the next 25,000 mobile search queries (rows 25,001-50,000) for a given date range. This is used for fetching data in batches when the total number of rows exceeds 25,000. ```python request = { 'startDate': flags.start_date, 'endDate': flags.end_date, 'dimensions': ['query'], 'dimensionFilterGroups': [{ 'filters': [{ 'dimension': 'device', 'expression': 'mobile' }] }], 'rowLimit': 25000, 'startRow': 25000 } ``` -------------------------------- ### Get Top 10 Mobile Queries in India Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics Retrieve the top 10 mobile search queries in India for a given date range, sorted by click count. Requires specifying the start and end dates, dimensions, and filters for country and device. ```python request = { 'startDate': flags.start_date, 'endDate': flags.end_date, 'dimensions': ['query'], 'dimensionFilterGroups': [{ 'filters': [{ 'dimension': 'country', 'expression': 'ind' }, { 'dimension': 'device', 'expression': 'MOBILE' }] }], 'rowLimit': 10 } ``` -------------------------------- ### Pseudocode for a Single Daily Query Source: https://developers.google.com/webmaster-tools/v1/how-tos/all-your-data This pseudocode demonstrates how to run a single daily query, fetching up to 25,000 rows at a time. It includes pagination logic to retrieve all available rows for a given day and data type. ```pseudocode int maxRows = 25000; // Current max response size int i = 0; do { response = Request(startDate = 3_days_ago, endDate = 3_days_ago, ... _add dimensions, type _... rowLimit = maxRows, startRow = i * maxRows); i++; … // Do something with the response data. } while (response.rows.count() != 0); // Page through all result rows ``` -------------------------------- ### Enable Gzip Compression with HTTP Headers Source: https://developers.google.com/webmaster-tools/v1/how-tos/performance To receive a gzip-encoded response, set the 'Accept-Encoding' header to 'gzip' and include 'gzip' in your User-Agent string. ```HTTP Accept-Encoding: gzip User-Agent: my program (gzip) ``` -------------------------------- ### Add a Site to Search Console Source: https://developers.google.com/webmaster-tools/v1/sites/add Use this PUT request to add a website property to your Search Console account. Ensure you have the correct authorization scope. The site URL is a path parameter. ```HTTP PUT https://www.googleapis.com/webmasters/v3/sites/siteUrl ``` -------------------------------- ### Add Maven Dependency Source: https://developers.google.com/webmaster-tools/v1/libraries Include this snippet in your `pom.xml` file to add the Google API Client Library for Java via Maven. ```xml Refreshing Maven content... ``` -------------------------------- ### Sites: list Source: https://developers.google.com/webmaster-tools/v1/sites/list Lists the user's Search Console sites. This method requires authorization with the `https://www.googleapis.com/auth/webmasters.readonly` or `https://www.googleapis.com/auth/webmasters` scope. No request body is supplied. ```APIDOC ## GET https://www.googleapis.com/webmasters/v3/sites ### Description Lists the Search Console sites that a user has access to, along with their permission levels. ### Method GET ### Endpoint https://www.googleapis.com/webmasters/v3/sites ### Authorization This request requires authorization with at least one of the following scopes: - `https://www.googleapis.com/auth/webmasters.readonly` - `https://www.googleapis.com/auth/webmasters` ### Request Body Do not supply a request body with this method. ### Response #### Success Response (200) If successful, this method returns a response body with the following structure: ```json { "siteEntry": [ sites Resource ] } ``` - `siteEntry` (list) - Contains permission level information about a Search Console site. For more information, see Permissions in Search Console. ``` -------------------------------- ### Add Gradle Dependency Source: https://developers.google.com/webmaster-tools/v1/libraries Include this snippet in your `build.gradle` file to add the Google API Client Library for Java via Gradle. ```gradle Refreshing Gradle content... ``` -------------------------------- ### Implement Test API Request Function Source: https://developers.google.com/webmaster-tools/v1/quickstart/quickstart-python This function retrieves a list of verified websites and their sitemaps using the Google Search Console API. It filters for verified URL-prefix sites and formats the output as an HTML table. Ensure credentials are saved back to the session. ```python @app.route('/test') def test_api_request(): if 'credentials' not in flask.session: return flask.redirect('authorize') # Load credentials from the session. credentials = google.oauth2.credentials.Credentials( **flask.session['credentials']) # Retrieve list of properties in account search_console_service = googleapiclient.discovery.build( API_SERVICE_NAME, API_VERSION, credentials=credentials) site_list = search_console_service.sites().list().execute() # Filter for verified URL-prefix websites. verified_sites_urls = [s['siteUrl'] for s in site_list['siteEntry'] if s['permissionLevel'] != 'siteUnverifiedUser' and s['siteUrl'].startswith('http')] # Print the sitemaps for all websites that you can access. results = '' for site_url in verified_sites_urls: # Retrieve list of sitemaps submitted sitemaps = search_console_service.sitemaps().list(siteUrl=site_url).execute() results += '' % (site_url) # Add a row with the site and the list of sitemaps if 'sitemap' in sitemaps: sitemap_list = "
".join([s['path'] for s in sitemaps['sitemap']]) else: sitemap_list = "None" results += '' % (sitemap_list) results += '
Verified siteSitemaps
%s%s
' # Save credentials back to session in case access token was refreshed. # ACTION ITEM: In a production app, you likely want to save these # credentials in a persistent database instead. flask.session['credentials'] = credentials_to_dict(credentials) return results ``` -------------------------------- ### Inspect URL Status Source: https://developers.google.com/webmaster-tools/v1/api_reference_index Get information about a provided URL in the Google index. Requires the inspection URL, its associated site URL, and a language code. ```json POST https://searchconsole.googleapis.com/v1/urlInspection/index:inspect { "inspectionUrl": "https://www.example.com/mypage", "siteUrl": "https://www.example.com/", "languageCode": "en-US"} ``` -------------------------------- ### list Source: https://developers.google.com/webmaster-tools/v1/sites Lists all websites associated with the user's Google Search Console account. ```APIDOC ## list ### Description Lists the user's Search Console sites. ### Method GET ### Endpoint /v1/sites ### Response #### Success Response (200) - **siteUrl** (string) - The URL of the property. - **permissionLevel** (string) - The user's permission level for the site. Acceptable values: `siteFullUser`, `siteOwner`, `siteRestrictedUser`, `siteUnverifiedUser` ``` -------------------------------- ### Sites List Source: https://developers.google.com/webmaster-tools/v1/api_reference_index Lists the user's Search Console sites. ```APIDOC ## GET /sites ### Description Lists the user's Search Console sites. ### Method GET ### Endpoint https://www.googleapis.com/webmasters/v3/sites ``` -------------------------------- ### Submit Sitemap Source: https://developers.google.com/webmaster-tools/v1/sitemaps/submit Submits a sitemap for a site using a PUT request to the specified endpoint. Requires authorization and includes path parameters for the sitemap URL and website URL. No request body is needed, and a successful submission returns an empty response body. ```APIDOC ## PUT /webmasters/v3/sites/siteUrl/sitemaps/feedpath ### Description Submits a sitemap URL to Google Search Console for a specified site. ### Method PUT ### Endpoint `https://www.googleapis.com/webmasters/v3/sites/siteUrl/sitemaps/feedpath` ### Parameters #### Path Parameters - **feedpath** (string) - Required - The URL of the sitemap to add. For example: `http://www.example.com/sitemap.xml` - **siteUrl** (string) - Required - The URL of the property as defined in Search Console. For example: `http://www.example.com/` (URL-prefix property), or `sc-domain:example.com` (Domain property). ### Authorization Requires authorization with the `https://www.googleapis.com/auth/webmasters` scope. ### Request Body Do not supply a request body with this method. ### Response #### Success Response (200) An empty response body indicates a successful submission. ``` -------------------------------- ### Get Top 10 Queries in India Source: https://developers.google.com/webmaster-tools/v1/how-tos/search_analytics Retrieves the top 10 search queries in India, sorted by click count. The 'equals' operator is the default for filters. ```python request = { 'startDate': flags.start_date, 'endDate': flags.end_date, 'dimensions': ['query'], 'dimensionFilterGroups': [{ 'filters': [{ 'dimension': 'country', 'expression': 'ind' }] }], 'rowLimit': 10 } ``` -------------------------------- ### Sites Add Source: https://developers.google.com/webmaster-tools/v1/api_reference_index Adds a site to the set of the user's sites in Search Console. ```APIDOC ## PUT /sites/siteUrl ### Description Adds a site to the set of the user's sites in Search Console. ### Method PUT ### Endpoint https://www.googleapis.com/webmasters/v3/sites/siteUrl ``` -------------------------------- ### Sites: add Source: https://developers.google.com/webmaster-tools/v1/sites/add Adds a site to the set of the user's sites in Search Console. This operation allows you to manage and monitor a website within your Search Console account. ```APIDOC ## PUT https://www.googleapis.com/webmasters/v3/sites/siteUrl ### Description Adds a website to the user's Search Console account, allowing it to be managed and monitored. ### Method PUT ### Endpoint https://www.googleapis.com/webmasters/v3/sites/siteUrl ### Parameters #### Path Parameters - **siteUrl** (string) - Required - The URL of the property to add. Examples: `http://www.example.com/` (for a URL-prefix property) or `sc-domain:example.com` (for a Domain property) ### Authorization This request requires authorization with the following scope: - `https://www.googleapis.com/auth/webmasters` ### Request Body Do not supply a request body with this method. ### Response #### Success Response (200) An empty response body indicates success. ``` -------------------------------- ### List Sites Response Structure Source: https://developers.google.com/webmaster-tools/v1/sites/list A successful response to the list sites request returns a JSON object containing a list of site entries. Each entry includes permission level information for a Search Console site. ```JSON { "siteEntry": [ sites Resource ] } ``` -------------------------------- ### list Source: https://developers.google.com/webmaster-tools/v1/sitemaps Lists the sitemaps submitted for this site, or included in the sitemap index file. ```APIDOC ## GET /sitemaps ### Description Lists the sitemaps-entries submitted for this site, or included in the sitemap index file (if `sitemapIndex` is specified in the request). ### Method GET ### Endpoint `/sitemaps` ### Parameters #### Query Parameters * **sitemapIndex** (string) - Optional - Specifies a sitemap index file to list sitemaps from. ``` -------------------------------- ### Query Data Grouped by Property (Greater Detail) Source: https://developers.google.com/webmaster-tools/v1/how-tos/all-your-data Use this query structure for greater detail when grouping by property, at the expense of some data. Optionally include 'query', 'country', or 'device' dimensions. ```json "startDate": "2018-06-01", "endDate": "2018-06-01", "dimensions": ["_query_", "_country_", "_device_"], "type": "web" ``` -------------------------------- ### Search Console Site Resource Representation Source: https://developers.google.com/webmaster-tools/v1/sites This JSON object represents a Search Console site and the user's permission level for it. It includes the site URL and the permission level, which can be one of several predefined values. ```json { "siteUrl": string, "permissionLevel": string } ``` -------------------------------- ### Second Query: Filter by Search Appearance Type Source: https://developers.google.com/webmaster-tools/v1/how-tos/all-your-data After identifying a search appearance type, use this query to get detailed data for that type, combined with other desired dimensions like device or page. This query filters results to include only 'AMP_BLUE_LINK'. ```json { "startDate": "2018-05-01", "endDate": "2018-05-31", "type": "web", "dimensions": [ "device" // and/or page, country, ... ], "dimensionFilterGroups": [ { "filters": [ { "dimension": "searchAppearance", "operator": "equals", "expression": "AMP_BLUE_LINK" } ] } ] } ``` -------------------------------- ### Query Search Traffic Data Source: https://developers.google.com/webmaster-tools/v1/searchanalytics Use this snippet to query your website's search traffic data. Specify the start and end dates for your query, along with the dimensions you want to group the results by. The API returns data sorted by click count. ```json POST https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.example.com%2F/searchAnalytics/query?key={MY_API_KEY} { "startDate": "2015-04-01", "endDate": "2015-05-01", "dimensions": ["country","device"] } ``` -------------------------------- ### Sitemaps Submit Source: https://developers.google.com/webmaster-tools/v1/api_reference_index Submits a sitemap for a site. ```APIDOC ## PUT /sites/siteUrl/sitemaps/feedpath ### Description Submits a sitemap for a site. ### Method PUT ### Endpoint https://www.googleapis.com/webmasters/v3/sites/siteUrl/sitemaps/feedpath ``` -------------------------------- ### List Sites HTTP Request Source: https://developers.google.com/webmaster-tools/v1/sites/list This is the HTTP request to list all Search Console sites a user has access to. It requires authorization and does not accept a request body. ```HTTP GET https://www.googleapis.com/webmasters/v3/sites ``` -------------------------------- ### Update API Scopes and Service Details Source: https://developers.google.com/webmaster-tools/v1/quickstart/quickstart-python Replace the Drive API configuration with the Search Console API details. This involves changing the SCOPES, API_SERVICE_NAME, and API_VERSION variables. ```python SCOPES = ['https://www.googleapis.com/auth/webmasters.readonly'] API_SERVICE_NAME = 'searchconsole' API_VERSION = 'v1' ``` -------------------------------- ### Update Ruby Client Library Source: https://developers.google.com/webmaster-tools/v1/libraries Update an existing google-api-client gem to the latest version using RubyGems. The -y flag automatically answers yes to any prompts. ```bash gem update -y google-api-client ```