Console error ('null') at lesson 5 youtube search api with javascript


#1

Lesson 5 of youtube search api with js i.e., Filtering responses with the 'q' parameter here I am facing a null error(not at codecademy environment) when running the code oin a browser.

In this link: https://www.codecademy.com/en/courses/javascript-intermediate-en-757J2/0/5?curriculum_id=50ecb8d45f787a6332000042

output is null, at console log of chrome this is the error message:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').

at firefox there is no error in the console but the page is still blank.
I have gone through stack overflow about it and found out the need to use webserver. And so I have installed http apache webserver and then run the code, but output is still the same.

Need some help about it please. Thanks.


#2

I am not able to reproduce this problem. May I ask you to post your code?

Here is an exemplary code that works for me:

function showResponse(response) {
  var responseString = JSON.stringify(response, '', 2);
  document.getElementById('response').innerHTML += responseString;
}

function onClientLoad() {
  gapi.client.load('youtube', 'v3', onYouTubeApiLoad);
}

function onYouTubeApiLoad() {
  gapi.client.setApiKey('AIzaSyCR5In4DZaTP6IEZQ0r1JceuvluJRzQNLE');
  search();
}

function search() {
  var request = gapi.client.youtube.search.list({
    part: 'snippet',
    q: 'riverside - second life syndrome'
  });
  request.execute(onSearchResponse);
}

function onSearchResponse(response) {
  showResponse(response);
}

#3

Here's my code:

function showResponse(response) {
var responseString = JSON.stringify(response, '', 2);
document.getElementById('response').innerHTML += responseString;
}

function onClientLoad() {
gapi.client.load('youtube', 'v3', onYouTubeApiLoad);
}

function onYouTubeApiLoad() {
// This API key is intended for use only in this lesson.
// See https://goo.gl/PdPA1 to get a key for your own applications.
gapi.client.setApiKey('AIzaSyCR5In4DZaTP6IEZQ0r1JceuvluJRzQNLE');

search();

}

function search() {
var request = gapi.client.youtube.search.list({
part: 'snippet',
q: 'boating',
});

request.execute(onSearchResponse);

}

function onSearchResponse(response) {
showResponse(response);
}

Also running your code gives exactly the same error to me


#4

I have the same problem with this code and actually any other snippet I’ve tried so far; did anyone find a solution?:thinking:


#5

factoradic posted the solution?

Anyway, this course (and the whole learning environment) are no longer supported. So i would advice against taking the course.

If you need more help, please make a new topic. This topic is really old, as such its now closed. See guidelines


#6