【问题标题】:Google Search Console API: Adding domains does not workGoogle Search Console API:添加域不起作用
【发布时间】:2022-01-05 09:34:39
【问题描述】:

我有此代码用于将新域添加到 Google 搜索控制台:

from googleapiclient.discovery import build
from googleapiclient._auth import credentials_from_file

service = build('searchconsole', 'v1', credentials=credentials_from_file('/md/setup/domains/service_account_key.json'))
sites = service.sites()
sites.add(siteUrl='https://www.mydomaindfvfvui4fu9neriern.com').execute()
print(sites.list().execute())
service.close()

它运行成功,然后列表显示域已添加:

{'siteEntry': [{'siteUrl': 'https://www.mydomaindfvfvui4fu9neriern.com/', 'permissionLevel': 'siteUnverifiedUser'}]}

但是,在https://search.google.com/search-console 的网络浏览器中,域没有显示。我在上面使用的密钥与我在浏览器中使用的 Google 帐户相关联。此外,我还有其他代码用于使用具有相同凭据的 siteVerification API 验证域。只有sites.add() 似乎以某种方式在其他实例上执行其操作。知道这里出了什么问题吗?

【问题讨论】:

  • 我相信这不起作用的原因是每个用户都有自己的搜索控制台状态。所以一切都作为服务用户工作。问题是,我无法以服务用户身份登录以在 Web 浏览器中管理我的域,并且据我所知,我无法将我的 Google 帐户用于 API。所以似乎不可能自动添加所有域让它们显示在网络浏览器中。

标签: python google-api-python-client google-search-console


【解决方案1】:

解决方案是使用 OAuth 流程以 Google 帐户用户身份登录。这已在此处得到证实: https://github.com/googleapis/google-api-python-client/issues/1647

完整的示例代码在这里: https://cloud.google.com/docs/authentication/end-user

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多