Google API - How to redirect URL to my localhost

后端 未结 2 1976
故里飘歌
故里飘歌 2021-01-01 02:53

I am working on integrating google login in my Phonegap app using Google OAuth. What happens is that while creating a client ID for my app, I have to choose \"Installed Appl

相关标签:
2条回答
  • 2021-01-01 03:24

    You can use Rewrite Rules too.

    For example, I need this callback for Google : http://local.dev/users/login-google

    So I have set this URL in Google Console : http://localhost/JUMP/local.dev/users/login-google

    And in apache, a simple redirect :

    RewriteEngine  on
    RewriteRule    ^JUMP/(.+)$   http://$1 [R,L]
    
    0 讨论(0)
  • 2021-01-01 03:26

    I have had the same issue recently. I also needed to figure it out for the Twitter API (answer found here).

    For google, I found 2 ways to fix the issue.

    1. Google will accept a localhost callback url. For example, if you are on a xampp server, and your redirect is saved under C:\xampp\htdocs\nozzle\callbacks\google.php then your redirect to give in the request (and in the Google API Console) would be: http://localhost/nozzle/callbacks/google.php Promblem Solved.
    2. If you are developing on a vhosted site: Redirect to a live site (or to somewhere in your localhost folder structure) to communicate with the google api and then serialize that data and send it to your url on your local virtual host.

    Option 2 requires some more explaining. Here's the breakdown:

    • I am developing locally on a virtual host. My data for my app is not in the localhost folder (http://myapp.dev). So I needed another solution that would allow me to still develop locally on a vhost, but also make requests to the Google API.
    • The Setup: the first call is made from http://myapp.dev/ but for the redirect, I use my live server address. Upon authorization from the user, Google redirects back to my live site where I make an additional call to the api. This info comes back (again to my live site) and I then serialize that info and redirect to http://myapp.dev/callback as a request by adding ?data= and put the serialized data at the end of that call. It then gets sent to my vhost site, and I retreive the data with $_REQUEST['data'], unserialize it, and I'm good to go.
    • This may seem like a lot of work, but for me and my team it is worth it to continue to work locally until we are ready to go live.

    Also, I imagine you could do the same process through a localhost address rather than a live one, but I have not tested that. But, if you do it with a live site, your whole team will be able to make the same requests from their local vhosts, as long as they are also vhosted at http://myapp.dev

    Foot Note: I am using the socialmedia-oauth-login tool for accessing the Google API.

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