jayshields / gmail-api-javascript-example

Example of how to use the Gmail API in JavaScript
3 stars 167 forks source link

issue authenticating #3

Open zoecarver opened 7 years ago

zoecarver commented 7 years ago

Hello, I am really interested in your gmail api js example. I have one question though, nothing happens when I click autherize. I have both my apikey and my client id, however nothing will happen. here is the code I am using:




  
    Gmail API demo
    

    
    
    
  
  
    

Gmail API demo

Not sure if this related, but I also get this error when I load the page.

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').

Thanks in advance! best, -Zoe

NateZimmer commented 7 years ago

Same issue, any luck figuring it out?

fhightower commented 7 years ago

I was able to avoid this error by running these files using a simple python http.server (You can also use a php server).

Even after using a local server, I still ran into a Load denied by X-Frame-Options: ... does not permit cross-origin framing error which I was not able to figure out. Let me know if anyone figures that one out.

naveennamani commented 7 years ago

While generating API key and clientId, you might have entered the authorized javascript origins URL's in console.developers.google.com. You need to call the gapi while you are on that URL domain. For example if you are on the localhost:4000/index.html page and calling gapi for signing in or whatever, you need to enter the authorized javascript origin as 'localhost:4000' in the google api console.

The google supports calls from localhost also, but with file:/// url domain, you cannot call google apis and it results in errors such as CORS.

So try to use a local server for the development, preferably nodejs. ( I just recommend, but you can use any local servers as you wish ).