当我尝试获取网站的站点地图但它显示以下错误时:
{'error': {'code': 401, 'message': 'API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal. See https://cloud.google.com/docs/authentication', 'errors': [{'message': 'Login Required.', 'domain': 'global', 'reason': 'required', 'location': 'Authorization', 'locationType': 'header'}], 'status': 'UNAUTHENTICATED', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'CREDENTIALS_MISSING', 'domain': 'googleapis.com', 'metadata': {'method': 'google.searchconsole.v1.SitemapsService.List', 'service': 'searchconsole.googleapis.com'}}]}}
Run Code Online (Sandbox Code Playgroud)
当我使用 Flask 并在浏览器上运行该项目时,它正在工作。我将访问令牌保留在烧瓶会话中,如谷歌记录的那样。
后来我尝试在没有 Flask 的情况下仅在桌面上运行该应用程序。所以我写了一个桌面的验证码。这是我的新代码,它不起作用:
SCOPES = ['https://www.googleapis.com/auth/webmasters']
API_SERVICE_NAME = 'searchconsole'
API_VERSION = 'v1'
def main():
"""Shows basic usage of the People API.
Prints the name …Run Code Online (Sandbox Code Playgroud)