https://developers.google.com/search/apis/indexing-api/v3/prereqs?hl=en_GB
官方文档
1. 在创建服务账号部分需要注意的是:
第二步授权要把服务账号的邮箱地址加上
2. 验证完网站站长之后需要注意的点
a. https://search.google.com/search-console/settings 进入"设置"里面,进入"用户和权限",点击"添加用户", 将刚才服务账号生成的邮箱添加进去,并且给他授权"所有者"
python 脚本批量推送的方法
successful=[]requests={url:"URL_UPDATED" for url in urls}JSON_KEY_FILE = 'path'SCOPES = ["https://www.googleapis.com/auth/indexing"]ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"# Authorize credentialscredentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE, scopes=SCOPES)# Build serviceservice = build('indexing', 'v3', credentials=credentials)def insert_event(request_id, response, exception):if exception is not None:print("error:",exception)if "RATE_LIMIT_EXCEEDED" in str(exception):print("need sleep!")else:successful.append(response['urlNotificationMetadata']['url'])batch = service.new_batch_http_request(callback=insert_event)for url, api_type in requests.items():batch.add(service.urlNotifications().publish(body={"url": url, "type": api_type}))batch.execute()# 批量插入之后,相应结果会进入回调"insert_event" 失败的会print出来为什么失败return successful
默认给的量是一个账号一天200个推送,但是可以申请更多,不过我没有成功过。解决方案也好搞,多搞点号,10个号一天就是2000个推送了。推送重置时间24个小时,我这边 测试 大致中国时间19点左右, 也就是15点能推200个,20点又能推200个。严格点控制完整的24小时即可
坑:
主要是这个报错
报错原因