Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Google API redirect URL

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.

like image 434
André Figueira Avatar asked May 13 '12 06:05

André Figueira


People also ask

What is dynamic HTTP redirection?

Dynamic Destination URL (DDU) allows you to redirect visitors to different destination URLs with the same tracking link by just adding a parameter. For example, this tracking link: 9nl.it/test_ddu normally redirects to www.clickmeter.com.

How do I redirect a URL to another URL?

Redirects allow you to forward the visitors of a specific URL to another page of your website. In Site Tools, you can add redirects by going to Domain > Redirects. Choose the desired domain, fill in the URL you want to redirect to another and add the URL of the new page destination.

What is an API redirect URL?

A redirect URI, or reply URL, is the location where the authorization server sends the user once the app has been successfully authorized and granted an authorization code or access token.


1 Answers

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'];
like image 89
Fraz Ahmed Avatar answered Sep 19 '22 14:09

Fraz Ahmed