3

I'm developing a PHP app on my local computer and trying to use the public data API. The key has been generated and works well online, but as soon as I try to execute it on my localhost it returns

Access Not Configured. Please use Google Developers Console to activate the API for your project.

I have added these lines to the 'allowed referers' section in the developers console.

http://127.0.0.1
127.0.0.1
http://localhost/
localhost
http://myIpAddress
myIpAddress

None of them seem to help. This is the query sending via GET:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=######&fields=items%2Fsnippet&key=#######
Emil Condrea
  • 9,705
  • 7
  • 33
  • 52
Ivan Lesar
  • 65
  • 1
  • 5

5 Answers5

2

My issue had nothing to do with the cases described here, but might help others.

I had a scenario where the API worked well online but not on localhost (WAMP), after migrating from old API.

The fix had to do with cURL, and I really can not explain why it did work online, I am not an expert, it's something related with SSL.

Basically, you need to turn of SSL verification, by using

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Hernan
  • 371
  • 1
  • 9
1

According to your answer @neki-doar-fraer, i make the explanation more clear for other viewers of this post :

From the doc of YouTube API

  • Use a server key if your application runs on a server. Do not use this key outside of your server code. For example, do not embed it in a web page. To prevent quota theft, restrict your key so that requests are only allowed from your servers' source IP addresses.

  • Use a browser key if your application runs on a client, such as a web browser. To prevent your key from being used on unauthorized sites, only allow referrals from domains you administer.

mpgn
  • 7,121
  • 9
  • 67
  • 100
0

From the Google Developer Console, assuming you have already created a project, select the project you are working on.

Then from the side menu on the left select "APIs & Auth", then "APIs". From that screen you have to search for the YouTube API and then click the "On" button next to it.

Harry12345
  • 1,144
  • 6
  • 20
  • 47
  • Already done. I've written in the question that it works online. 'localhost' is the problem. – Ivan Lesar Sep 14 '14 at 14:03
  • 1
    Have you tried adding `http://localhost` to the JavaScript origins on the Credentials page? – Harry12345 Sep 14 '14 at 14:28
  • I don't uderstand what you mean by JavaScript origins. I have a javascript file which calls a php file by an ajax request. Did you mean that I should include the full path to the javascript file like 'http://localhost/.../javascriptFile.js'? – Ivan Lesar Sep 14 '14 at 18:24
  • I meant in the Google Developer Console, under the Credentials tab on the left. There is a section called Javascript Origins there – Harry12345 Sep 14 '14 at 18:37
  • Oh. I see. But that's for OAuth. I'm using the public data api. I mentioned it in the post. – Ivan Lesar Sep 14 '14 at 20:13
  • According to [this question](http://stackoverflow.com/questions/20189688/uploading-video-to-youtube-using-youtube-data-api-v3-and-google-api-client-php?rq=1) You need to make sure that your Google client account is linked with you YouTube account – Harry12345 Sep 15 '14 at 08:22
0

I figured it out. I was using the browser key. Did not know there is a difference. Generated the server key and everything works.

Ivan Lesar
  • 65
  • 1
  • 5
0

I have always edited my HOSTS file to point the domain to LOCALHOST when testing things locally https://en.wikipedia.org/wiki/Hosts_(file)

Joe
  • 677
  • 1
  • 6
  • 13