【发布时间】: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