Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Handle Google API Response

$
0
0

I want to get the comments from a YouTube video and do some further work with them. I started with the implementation example from the docs for "CommentThreads: list" and continued from there on.

Using a main function I want to call the execute function and use the response it should return. It should look kinda like the following:

function execute() {  return gapi.client.youtube.commentThreads.list({"part": ["snippet"    ],"fields":["items/snippet/topLevelComment/snippet(authorDisplayName,authorProfileImageUrl,publishedAt,textDisplay)"    ],"videoId": "XXXXX"  }).then(function(response) {              console.log(response.result);            },            function(err) {               console.error("Execute error", err);             });}function main(){  let response = execute();  console.log(response);}

And the output in the console looks like this:

{"Ca": 2,"yb": null,"Yj": null,"Sn": null,"KB": false,"xw": false}

Another way I tried to solve this is to not return gapi.client.youtube.commentThreads.list but the response in the successful promise function like so:

function execute() {  gapi.client.youtube.commentThreads.list({"part": ["snippet"    ],"fields":["items/snippet/topLevelComment/snippet(authorDisplayName,authorProfileImageUrl,publishedAt,textDisplay)"    ],"videoId": "XXXXX"  }).then(function(response) {              console.log(response.result);              return reponse.result;            },            function(err) {               console.error("Execute error", err);             });}

But here I only get an undefined.

I am just learning JavaScript and the use of the API.


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>