Google API redirect dynamic URL

I am encoding a Google contacts import code for a social network, this import occurs on the user’s page, which will differ from user to user, for example. profile / user1, profile / user2

However, with google, I seem to be able to set only one redirect URL and cannot find any mention that Google allows wildcards to match the domain, and not the specific URL.

Is there a way to do this, or do I just need to leave it at one URL?

Thanks in advance.

+6
source share
5 answers

I have PHP code to achieve it. This is not to say that this is impossible. I used this method for Google Analytics, Adwords, Google+ and YouTube. He worked with all the services mentioned.

Trick should use the state parameter, which will be used as a dynamic URL. Hope this helps everyone.

// Auth URL // $campaign_id will be different for everyone $dynamic_redirect = 'http://' . $_SERVER['HTTP_HOST'] . "/analytics/$campaign_id"; $client_id = 'XXXXXXXX'; $redirect_uri = 'API_REDIRECT_URI'; // Fixed URL, it will not be changed $auth_url = "https://accounts.google.com/AccountChooser?service=lso&continue="; $auth_url .= urlencode("https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.googleapis.com/auth/analytics.readonly&access_type=offline&redirect_uri=$redirect_uri&approval_prompt=force&state=$dynamic_redirect&client_id=$client_id"); /*************************************/ API_REDIRECT_URI PAGE /*************************************/ $redirect_url = $_GET['state']; 
+12
source

I found this to be impossible, so if someone is looking for it, there is no way. I ended up fixing my problem by simply allowing Google to redirect to a fixed URL rather than a dynamic one.

+6
source

You can do one simple thing. Put the URL of the user page in the session when creating the URL. On the Callback page, enter the "custom page URL" from the session and simply redirect the user to this page.

I managed to succeed using PHP.

+1
source

Perhaps since I know an application that does this. I found this post on how to do this - have not tried it yet, but it's worth it: http://www.ioncannon.net/programming/1443/google-oauth-for-installed-apps-php-example/

0
source

We can specify multiple redirect URIs in the Google API settings, one per line

Google API Console → Choose your API → API Access → Change Settings → In the redirect authorization URI section

enter ..

http://one.example.com/contactimporter.php

http://two.example.com/contactimporter.php

0
source

Source: https://habr.com/ru/post/915589/


All Articles