migueesc123 / YoutubeAnalytics

A Microsoft Data Connector or Power Query Connector for YoutubeAnalytics data
MIT License
61 stars 21 forks source link

How do you make the click handler wait for the api to load? #11

Closed BrentGrammer closed 6 years ago

BrentGrammer commented 6 years ago

Hi, this may not be relevant to this project, but I posted a question on your youtube video and was instructed to post on the github page - I hope this is okay and my question is in the right area.

I am trying to make a call to the youtube data API v3, and am finding that the click handler on my button to make the call can fire the handler making the call before the API client library is loaded. How do you make the click handler wait (to function like a promise, for example) so that the call function will not fire until all necessary api components have finished loading. Pics of my code are attached and a pic of the error that happens if the button is clicked before the API loads. Thank you for any help.

Index.html with button that makes the API Call:

indexhtml Scripts file loaded into index.html:

scripts

The error when btn is clicked too soon (shown in console in devtools):

asyncerror Just to be clear, the call and the button works, it's just that if it is clicked too soon, there will be an error - I want to make it so that when the button is clicked, even if it is too soon, the handler will wait for all of the API to load before it fires the call. Thanks again.

migueesc123 commented 6 years ago

Hey Brent!

I wish that I could help you, but I'm not familiar with Javascript. The code that I created used the M language from Microsoft's Power Query and some simple HTTPS requests. The video on YouTube was mainly created for the topics covered in this repo and to follow the step by step guide that I have on it.

I'd recommend that you try posting your question on the dedicated forums for the API or perhaps on Stackoverflow.

Sorry that I couldn't be of more help.

BrentGrammer commented 6 years ago

Ok, thank you for responding anyways. -Brent

On Fri, May 4, 2018 at 11:39 PM, Miguel Escobar notifications@github.com wrote:

Hey Brent!

I wish that I could help you, but I'm not familiar with Javascript. The code that I created used the M language from Microsoft's Power Query and some simple HTTPS requests. The video on YouTube was mainly created for the topics covered in this repo and to follow the step by step guide that I have on it.

I'd recommend that you try posting your question on the dedicated forums for the API or perhaps on Stackoverflow.

Sorry that I couldn't be of more help.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/migueesc123/YoutubeAnalytics/issues/11#issuecomment-386781319, or mute the thread https://github.com/notifications/unsubscribe-auth/Ahm5ISosQsrH0RVJes7ZRP_uHCdu5Resks5tvTr4gaJpZM4TzYyb .