Google API in Javascript

前端 未结 4 1981
半阙折子戏
半阙折子戏 2020-11-29 11:10

I am trying to get calendar info from google in javascript. I ve read \'how to\' manuals. They didn\'t help. Even this \'helpful\' copypasted code (to authorize) didn\'t. Wo

相关标签:
4条回答
  • 2020-11-29 11:39

    Some APIs will work fine when queried from local files, but some won't. In response to an error such as yours, try to serve your files from a web server. If you need a quick web server running, use Python's builtin HTTP server (Mac OSX and Linux systems have Python pre-installed). This HTTP server can turn any directory in your system into your web server directory. cd into your project directory and run the following command: python -m SimpleHTTPServer 3000 The number at the end is the port number your http server will start in and you can change that port number. In our example, your directory would be served from: http://localhost:3000.

    0 讨论(0)
  • 2020-11-29 11:41

    Google API Console reference :

    In Client ID for web application:

    Javascript Origins : http://localhost:3000/


    Key for browser applications:

    Referers : http://localhost:3000/

    localhost would work 100%

    0 讨论(0)
  • 2020-11-29 11:41

    i got the same error and as you preferred, after running html file in my local web server problem solved.

    i created credentials for web application and set following values both to my local with "http://localhost:5000" string

    "Authorized JavaScript origins" 
    "Authorized redirect URIs
    

    i checked the json file too. i got the following json file as a result.

    {"web":
     {
        "client_id":"myClientID",
        "project_id":"my-project",
        "auth_uri":"https://accounts.google.com/o/oauth2/auth",
        "token_uri":"https://accounts.google.com/o/oauth2/token",
        "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
        "client_secret":"XqXmgQGrst4xkZ2pgJh3Omxg",
        "redirect_uris":["http://localhost:5000"],
        "javascript_origins":["http://localhost:5000"]
     }
    

    }

    https://developers.google.com/drive/v2/web/auth/web-client

    0 讨论(0)
  • 2020-11-29 11:53

    Based on the error you're receiving, my guess is that you either do not have your Javascript Origin configured properly on the Google API console you got your Client ID from, and/or you are trying to run your script from the file system instead of through a web server, even one running on localhost. The Google API client, near as I've been able to tell, does not accept authorization requests from the file system or any domain that has not been configured to request authorization under the supplied Client ID.

    0 讨论(0)
提交回复
热议问题