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
是我在要点中找到的代码。它似乎工作并给出了很好的响应,但是当我搜索我的网站时,什么都没有出现!我很心烦意乱。我很难过。也很沮丧。我不想放弃。