Reputation: 6696
I am coding a google contacts import code for a social network this import happens on the user page which the url will vary from user to user e.g. profile/user1, profile/user2
However with google I seem to be able to set only one redirect url and can't seem to find any mention of google allowing wildcards to match the domain instead of the particular url.
Is there a way of doing this or will I have to just leave it set to one url?
Thanks in advance.
Upvotes: 9
Views: 12581
Reputation: 298
I have the PHP code to achieve it. It is wrong to say that it cannot be done. I used this technique for Analytics, Adwords, Google+ and YouTube. It worked with all mentioned services.
Trick is to use "state" parameter to be used as dynamic URL. I hope it will help 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'];
Upvotes: 19
Reputation: 369
We can specify the multiple Redirect URIs in the Google API Settings, one per line
Google API Console -> Select your API -> API Access -> Edit Setting -> Under Authorize Redirection URI
enter..
http://one.example.com/contactimporter.php
http://two.example.com/contactimporter.php
Upvotes: -2
Reputation: 1742
It is possible, as I know of an app that does this. I found this post on how to do it - haven't tried it yet, but it's worth a shot: http://www.ioncannon.net/programming/1443/google-oauth-for-installed-apps-php-example/
Upvotes: 0
Reputation: 298
You can do one simple thing. Put "user page url" in session when creating Auth URL. On your Callback page get "user page url" from session and simple redirect user to that page.
I was able to achieve above successfully using PHP.
Upvotes: 1
Reputation: 6696
I have found that this is not possible, so if anyone is looking for this, there isn't a way. I ended up fixing my issue by just letting google redirect to a fixed url so not a dynamic one.
Upvotes: 6