17

I thought this would be straight forward, but for some reason I'm getting hammered on this one.

I'm using PHP + CURL to try and retrieve a list of Web Fonts. The code is simple:

        $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);            

The code is hitting Google, but $google_response always returns:

"error": {
    "code": 403,
    "errors": [
        {
            "domain": "usageLimits",
            "reason": "accessNotConfigured",
            "message": "Access Not Configured"
        }
    ],
    "message": "Access Not Configured"
}

I've set up a server access key and put both of my web server's API keys on it. (To verify my IP, I did a WGET on curlmyip.com) I've also enabled the "Web Fonts Developer API" from the Services tab.

Is there anything I could be overlooking?

Anthony
  • 5,275
  • 11
  • 50
  • 86

5 Answers5

21

I found the solution. Apparently I needed to register my server's IPv6 address, not the IPv4's. Worked without any code changes after adding them.

Anthony
  • 5,275
  • 11
  • 50
  • 86
  • Hey Anthony. where should one do that configuration ? – Kiran Ruth R Apr 02 '13 at 11:10
  • 8
    @KiranRuthR It's surprisingly hidden. Visit https://code.google.com/apis/console. First, make sure the service you want is enabled under "Services". Then go to "API Access" and specify your calling domains or IP addresses. – Anthony Apr 04 '13 at 13:31
  • @Anthony: Even I am facing the same problem using my localhost. Should i add IPv6 of my localhost? – curious_coder Jun 26 '13 at 04:46
  • 1
    @curious_coder I have no idea whether localhost will work. Most likely it'd be the IP address of your machine. Try going to whatismyv6.com and provide that, since that is where your traffic will be calling from. – Anthony Jun 26 '13 at 15:20
  • Thank you... I already had localhost in but had not turned on access for Calendar. – Ezekiel Victor Aug 25 '13 at 04:39
  • It works for me. I had to define the IPv6 address, because "any IP allowed" didn't worked for me. Tak care! – Athlan Oct 22 '13 at 17:32
  • I've converted my IPv4 into an IPv6 address, but Google says it's not a valid address... This is what I'm trying to enter: 2002:0:0:0:0:0:400d:c03c – bart Feb 20 '14 at 07:43
14

In my case the needed API was not enabled.

To enable:

  1. Go to https://console.developers.google.com
  2. Click the menu icon in the top left
  3. Click API Manager from the menu
  4. Search for your API in the search bar (e.g. YouTube Data API v3) and click on it
  5. Once on the subpage for that API, click Enable in the top left
Nelu
  • 16,644
  • 10
  • 80
  • 88
4

remove all "allowed Ips", then Any IP allowed

Baryon Lee
  • 1,157
  • 11
  • 11
  • Brayon, Explain how you configured allowed Ips? – Parthasarathy B Jun 07 '14 at 16:31
  • Thank you. Yes, removing all allowed IPs worked for my "Public API access" server key. It didn't work immediately (testing with cli curl) , so I regenerated the key. The new one worked immediately, but a few minutes later the original worked as well. – dbenton Jul 30 '14 at 19:45
0

I attempted the solutions listed above in order and wasn't able to get a result. The YouTube, Dialogflow and Google+ API integrations had been inactive for a few months when this happened.

Eventually the only solution was:

  • Create a new project
  • Create a new key
  • Copy the IPv4 and IPv6 Addresses under the Application Restrictions
  • Update the API restrictions based on the needs of you application
Eric Kigathi
  • 1,815
  • 21
  • 23
0

For anyone receiving similar errors but not knowing what the actual problem is, make sure to set

curl_setopt($ch, CURLOPT_FAILONERROR, false);

in order to receive a valid CURL response, which includes the error description from Google.

mavrosxristoforos
  • 3,573
  • 2
  • 25
  • 40