google indexing api 不工作,如何使它工作?

问题描述

from oauth2client.service_account import ServiceAccountCredentials
import httplib2
import json


# https://developers.google.com/search/apis/indexing-api/v3/prereqs#header_2
JSON_KEY_FILE = "key.json"
ScopES = ["https://www.googleapis.com/auth/indexing"]


def indexURL(urls):
    credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE,scopes=ScopES)
    http = credentials.authorize(httplib2.Http())
    ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"
    
    for u in urls:
    
        content = {}
        content['url'] = u.strip()
        content['type'] = "URL_UPDATED"
        json_ctn = json.dumps(content)
        response,content = http.request(ENDPOINT,method="POST",body=json_ctn)
        result = json.loads(content.decode())
        print(result)
        try:
          if result['error']:
            return False
          else:
            return True
        except:
          return True

是我在 gist 中找到的代码。它似乎有效并给出了很好的回应等等,但是当我搜索我的网站时,什么也没有出现!我心烦意乱。我很难过。也很沮丧。我不想放弃。

解决方法

您可以查看google notification status