Dynamic Google API redirect URL - google-contacts-api

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.

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'];

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.

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.

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/

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

Related

Docusign redirect url with dynamic domain name

currently my local account have different domain like "http://tester.company-dev:8080" , when ever i create an account i will get different domain . how will i set the redirect url in setting page in docusign so that it will redirect me to correct domain url . is it possible to pass a parameter to redirect_url something like below :
"http://{domain}.company-dev:8080/ds/callback" and i need to pass the domain value
here domain=tester
I assume you mean the URL for OAuth, mostly used for Auth Code Grant to redirect users back to your app with the code needed to obtain an access token.
You would have to know all the possible URLs and add them to your IK. There's no way to make this dynamic. This is arequirement of OAuth2.0 specification, it's a security issue and you have to have a matching URL. If there's a reason you cannot do that, we can suggest alternate solutions that may involve not using Auth Code Grant and/or some redirect scheme from a fixed URL to one of these dynamic ones.

Drive API multi login iframe issue

I am using drive api in my app and it works well , but sometimes when multiple users are logged in and I try to open a file in the browser with the link fetched via drive api I see the error message "You need permission. Want in? Ask the owner for access, or switch to an account with permission. Learn more" .
Steps to reproduce :
login to google drive with one account.
login with a second account and use drive api.
when you try to open public files you get that error.
If you add access token in url it seems to resolve the issue but thats a security risk. If you add authuser param to url that also works, but I can't find a way to get current user's authuser param.
Any help is appreciated.

Google Maps URL parameter "pw=2" does not work anymore

On our website, we have a store locator using Google Maps. Users can also plan a route to a store and print it. To open a print view, we used URL parameter pw=2 successfully, but since a few days/weeks the param leads to a 404 page.
Example:
http://maps.google.com/maps?saddr=74321&daddr=70378 works, whereas
http://maps.google.com/maps?saddr=74321&daddr=70378&pw=2 leads to a 404.
Does anybody know a workaround or a substitute for the pw=2 param?

google drive sdk - What are the JavaScript Origins and Authorized Redirect URLs?

While creating the Client_ID I am stuck in these two textboxes (JavaScript Origins and Authorized Redirect URLs) appearing on that PopUp. I am not able to search the internet about those two things.
In a tutorial it was written that we just need to put our hostnames there! But why? What do they actually mean?
Hope I am clear.
Any help would be appreciated.
If you're using the JavaScript client, you need to set a valid JavaScript origin for us to authorize you.
Authorized redirect URIs are the endpoints we're going to call as a callback if you're using 3-legged OAuth 2.0 flow. https://developers.google.com/accounts/docs/OAuth2#webserver illustrates a sequence where Google endpoints pushes a code to your application. Push is done by calling a redirect url with a code query parameter.
http://yoursite/callback?code=[code to exchange]

Looking to use google drive realtime API with google+ hangout application

I currently have a hangout application and I'd like to add some collaborative functionality to it given the realtime API.
Following the realtime API quickstart guide (adding two text areas and a button to authorize with), I've added the relevant code to the hangout XML module(Is this the correct name for this?)
It looks like, however, whenever I click the "authorize" button from within the google hangout instance, the page might refresh (or something?) and a GET request comes back with a: 400 (Bad Request) response.
Is there something I've overlooked?
Perhaps, some documentation I missed?
Is there a better approach to what I'm trying to accomplish?
EDIT: More information on the GET request and response from chrome's javascript console:
https://015isqam6kq3vfnd0h572bpk4rvnem82-a-hangout-opensocial.googleusercon…dgets/ifr?fileId=0B2FRfMTFpkH0S3RDUlhDMWNsbjQ&userId=103345858281489162915 400 (Bad Request) 015isqam6kq3vfnd0h572bpk4rvnem82-a-hangout-opensocial.googleusercontent.com…ets/ifr?fileId=0B2FRfMTFpkH0S3RDUlhDMWNsbjQ&userId=103345858281489162915:1
The page (where the hangout content should be) then shows:
"Missing or malformed url parameter"
The problem lies in the realtime-client-utils.js that the documentation provides.
The idea with the authorization is that upon authorization, it tries to redirect the page via window.location.href and adds parameters to the end of the URL.
Removing the redirect, setting the parameters in the parameters object manually, and restarting the authorization process fixes the problem.