0

I am new to web development and am trying to make a very simple search page that displays YouTube videos using the YouTube API. I've been following the examples from here: https://developers.google.com/youtube/v3/code_samples/javascript?hl=fr#search_by_keyword but I'm not having a lot of luck. I have no errors but no search results either.

My current code is here: http://amalthea5.github.io/thinkful-tube/

2 Answers 2

1

There seems to be several problems. You need to use

<script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>

instead of

<script src="https://apis.google.com/js/client.js?onload=onClientLoad" type="text/javascript"></script>

because you need to make sure the initialization function googleApiClientReady() in auth.js is called.

However, the Google API also reports that there exists no OAuth client with the ID trusty-sentinel-92304.

Edit:

If don't have an OAuth client ID, but rather an API key, you shouldn't use the auth API at all. Instead, you need to add the API key as parameter to each API call (as described here: https://developers.google.com/youtube/v3/docs/standard_parameters).

Try this as a start:

gapi.client.load('youtube', 'v3', function() {
  var request = gapi.client.youtube.search.list({
    key: "YOUR_API_KEY",
    q: "cats",
    part: 'snippet'
  });

  request.execute(function(response) {
    var str = JSON.stringify(response.result);
    console.log(str);
  });
});
Sign up to request clarification or add additional context in comments.

2 Comments

Ok I changed the script as you stated. And I looked into the client ID. I was initially trying to do it using the API key I got from the Google Developers Console, which is not the same as the OAuth client. I don't have an OAuth client ID, just a project ID. So how would I go about this using my API key? Thank you so much for helping this clueless noob.
You could probably also use gapi.client.setApiKey() to specify your API key, so you don't need to include it as a parameter to every query.
0

To begin with if you read the very tutorial you are following again, it says that:

Again, you need to update the client ID in the auth.js file to run this code.

Which looks like you didnt,

also by running a search query from the console I get the following error:

TypeError: gapi.client.youtube is undefined

Meaning the api is not initiated, You should double check the way you embed the google javascript file and the priority of doing so (the order of them)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.