Google API返回未配置的访问权限

Ant*_*ony 16 google-api http-status-code-403

我认为这将是直截了当的,但由于某种原因,我正在受到这一点的打击.

我正在使用PHP + CURL来尝试检索Web字体列表.代码很简单:

        $url = "https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key=MY_SERVER_APPS_KEY";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $google_response = curl_exec($ch);
        curl_close($ch);            
Run Code Online (Sandbox Code Playgroud)

该代码正在攻击Google,但$ google_response始终返回:

"error": {
    "code": 403,
    "errors": [
        {
            "domain": "usageLimits",
            "reason": "accessNotConfigured",
            "message": "Access Not Configured"
        }
    ],
    "message": "Access Not Configured"
}
Run Code Online (Sandbox Code Playgroud)

我已经设置了一个服务器访问密钥,并将我的两个Web服务器的API密钥放在上面.(为了验证我的IP,我在curlmyip.com上做了一个WGET)我还从服务选项卡启用了"Web Fonts Developer API".

有什么我可以俯瞰的吗?

Ant*_*ony 20

我找到了解决方案.显然我需要注册我的服务器的IPv6地址,而不是IPv4.添加后没有任何代码更改工作.

  • @KiranRuthR令人惊讶地隐藏起来.访问https://code.google.com/apis/console.首先,确保在"服务"下启用所需的服务.然后转到"API访问"并指定您的呼叫域或IP地址. (8认同)

Nel*_*elu 13

在我的情况下,未启用所需的API.

启用:

  1. 转到https://console.developers.google.com
  2. 单击左上角的菜单图标
  3. 单击API Manager菜单
  4. 在搜索栏中搜索您的API(例如YouTube Data API v3)并单击它
  5. 进入该API的子页面后,单击Enable左上角的