【问题标题】:In mobile friendly test api I am getting API Key not found, Please pass a valid API key error在移动友好的测试 api 中我得到 API Key not found, Please pass a valid API key 错误
【发布时间】:2019-07-18 12:06:21
【问题描述】:

我正在尝试在我的网站中提供移动友好的测试选项。为此我正在测试路径是否有效?

以下是我在 Mac OS 终端中运行的 curl 命令。

curl -H 'Content-Type: application/json' --data '{url: "https://www.some-site.in"}' 'https://searchconsole.googleapis.com/v1/urlTestingTools/mobileFriendlyTest:run?key=xxxxxxxxxxxxxxxxxxxxxx'

但我收到以下错误:

{ “错误”:{ “代码”:400, "message": "未找到 API 密钥。请传递一个有效的 API 密钥。", “状态”:“INVALID_ARGUMENT”, “细节”: [ { "@type": "type.googleapis.com/google.rpc.Help", “链接”:[ { "description": "Google 开发者控制台 API 密钥", "网址": "https://console.developers.google.com/project/xxxxxxxxxx/apiui/credential" } ] } ] } }

注意:我已将 api key 和 project id 替换为 xxxxx...

在谷歌开发者控制台中,我创建了一个项目,然后我创建了一个 api 密钥,我在开发者控制台中使用我的计算机 IP 地址限制了 api 密钥。我还尝试了另一个没有限制键的 api 键。

但在所有情况下都会出现上述相同的错误。

我也尝试过使用 PHP 脚本和 curl 方法并得到 400 错误。我也尝试过使用 ajax 并得到了同样的错误。

我无法找到到底出了什么问题。请指导我。谢谢。

【问题讨论】:

    标签: curl google-api


    【解决方案1】:

    您需要在“APIs and Services”->“Library”下启用Google Search Console URL Testing Tools API

    然后将密钥作为参数传递(不在帖子正文中,他们网站上的示例对我不起作用) 这有效:

    api_key="YOUR_KEY"
    import requests
    request_url = 'https://selenium-python.readthedocs.io/api.html'
    service_url = f'https://searchconsole.googleapis.com/v1/urlTestingTools/mobileFriendlyTest:run?key={api_key}'
    params = {
        'url': request_url,
    }
    
    print(requests.post(service_url, json=params).json())
    

    【讨论】:

      【解决方案2】:

      您需要在“APIs and Services” -> “Library”中启用 API 才能使用 API 密钥。

      【讨论】:

      • 将此添加为评论
      猜你喜欢
      • 2022-09-06
      • 2016-06-06
      • 2021-10-28
      • 1970-01-01
      • 2014-06-18
      • 2022-08-06
      • 1970-01-01
      • 2021-01-12
      • 1970-01-01
      相关资源
      最近更新 更多