如何在 Google Search Console(网站站长工具)API 版本 3 中完成网站验证?

How can I complete site verification in Google Search Console (Webmaster Tools) API version 3?

我正在使用 Search Console API 添加网站并在添加后从中获取信息。不幸的是,API 参考文献很少,到目前为止我所能做的就是提交网站进行初始验证 - 然后一旦我上传了验证文件或元标记,我就必须登录到 google帐户并手动单击 "Verify" 按钮,破坏了 API.

的目的

我知道 API 的早期版本允许您通过发送另一个请求来完成验证。由于 v3 的文档缺少大量信息并且通常通常不正确,我希望其他人知道如何执行此操作。

用于验证网站所有权的方法已在旧 API 版本中弃用,不再受支持。 因此,不再需要通过 API.

验证站点所有权

请参阅 Developer's Guide: Protocol 了解详情。

改用Google Site Verification

要求:

POST https://www.googleapis.com/siteVerification/v1/token?access_token=oauth2-token
Content-Type: application/json

{
  "verificationMethod": "META",
  "site": {
    "identifier": "http://www.example.com",
    "type": "SITE"
  }
}

回复:

{
  "token": '<meta name="google-site-verification" content="lZgPSX9UM01PXeMi88RGdIrBpl7jLFCXL9RNt4N0mmo" />',
  "method": "META"
}

阅读此内容了解更多信息: https://developers.google.com/site-verification/v1/invoking#verify