egeloen / IvoryGoogleMapBundle

Google Map API v3 integration for your Symfony2 project.
https://github.com/egeloen/ivory-google-map
MIT License
217 stars 152 forks source link

Add client id for business application #87

Closed anthonytison closed 11 years ago

anthonytison commented 11 years ago

Hi,

Could you please add the possibility to set a client id ?

I need to bind my business account with your bundle.

Thank you

egeloen commented 11 years ago

Can you elaborate a bit please?

anthonytison commented 11 years ago

Yes of course. I have a business account in order to increase the maximum of requests for getting directions, geocoding...

So in order to use my account, i must include my client id into the google apis url (ex: http://maps.googleapis.com/maps/api/directions/json?client=[clientID]) and also calculate the signature with a crypto key provided by Google.

You can have more information here : https://developers.google.com/maps/documentation/business/clientside/

It could be great to set 2 more parameters (clientID & cryptoKey) in config.yml and have them directly in all api calls.

I hope my explanation will help you to understand my need.

Thanks

egeloen commented 11 years ago

Okay, I think I got it :) IMO, your link is wrong as it is about client side (JS), this one (https://developers.google.com/maps/documentation/business/webservices) is better. Is it what you want?

anthonytison commented 11 years ago

Indeed the link was wrong ;) and yes it's exactly what i need. I hope you will be able to improve your bundle with this feature.

egeloen commented 11 years ago

What is the service you would like to get first? Geocoder or an other? I ask this question because the Geocoder does not use the same implementation than the others.

anthonytison commented 11 years ago

The directions service will be great. Thx

egeloen commented 11 years ago

@anthonytison I have push a proposal in the referenced PR. Can you try it with you own account?

anthonytison commented 11 years ago

@egeloen I definitely miss something.

I've created a new BusinessAccount with my account datas but how bind the directions service with my business account. Is it automatic or do i have to use a setter ?

So far the directions service url gets no clientID and no secret key.

egeloen commented 11 years ago

@anthonytison My PR is not finished (missing some tests & all the doc...). To test it you need to set a business account on the service & then everything is done automatically.

$directions->setBusinessAccount(new BusinessAccount('client_id', 'secret'));
$reponse = $directions->route('Washington', 'Mexico');

Basically, I have not tested it as I have no business account... So, IMO, there is probably something wrong in AbstractService::signUrl. I let you give me some feedbacks :) I have based my implementation according to https://developers.google.com/maps/documentation/business/webservices/auth & http://gmaps-samples.googlecode.com/svn/trunk/urlsigning/UrlSigner.php-source

anthonytison commented 11 years ago

@egeloen I've tested with my business account and i got this error :

Argument 1 passed to Ivory\GoogleMap\Services\Directions\Directions::buildDirectionsResponse() must be an instance of stdClass, null given, called in /vendor/egeloen/google-map/src/Ivory/GoogleMap/Services/Directions/Directions.php on line 70 and defined in /vendor/egeloen/google-map/src/Ivory/GoogleMap/Services/Directions/Directions.php line 222

For the url signing functions, i used the same script on the master branch of my project and it works very well so i have no doubt it will work in this case too :)

egeloen commented 11 years ago

Okay, if you got this error means the http adapter does not return a valid json response (json_decode returns null when it fails). Can you check what is the value of $response here: https://github.com/egeloen/ivory-google-map/blob/0f8576b83da1867c529935a7effe631a8d7c3767/src/Ivory/GoogleMap/Services/Directions/Directions.php#L69

egeloen commented 11 years ago

And at the same time, check if the generated url seems valid.

egeloen commented 11 years ago

@egeloen A note for me, add a check if json_decode fails in all services.

anthonytison commented 11 years ago

First of all, i had twice the prefix gme- as a client ID value and signature was wrong. Now the url is fine but the signature is not valid for my client ID.

This is what i get :

'Unable to authenticate the request. Provided \'signature\' is not valid for the provided client ID. Learn more: https://developers.google.com/maps/documentation/business/webservices/auth'

egeloen commented 11 years ago

When google provide you the client ID, is it prefixed by gme-? By default, you should provide your client_id without the gme- prefix as it is prepended automatically according to the spec.

anthonytison commented 11 years ago

Yes of course this is why i add a doublon in the url on my first test. Now the url has just one gme- prefix.

This is what it looks like :

http://maps.googleapis.com/maps/api/directions/json?origin=48.8913%2C2.34023&destination=49.637925349982%2C2.5853607190322&mode=driving&units=metric&region=FR&language=fr&sensor=false&client=gme-[CLIENT_ID]&signature=[SIGNATURE]

egeloen commented 11 years ago

So, does it work?

anthonytison commented 11 years ago

Nop apparently the signature is not valid.

'Unable to authenticate the request. Provided \'signature\' is not valid for the provided client ID. Learn more: https://developers.google.com/maps/documentation/business/webservices/auth'

egeloen commented 11 years ago

I just push a fix. Can you retry plz?

anthonytison commented 11 years ago

It works now :)

Let me know when you will merge this new feature on the master branch and i will make an update via composer.

Thank you so much.

egeloen commented 11 years ago

:+1:

egeloen commented 11 years ago

@anthonytison Everything is merged in master. I just integrates the change in the bundle. See #90 & https://github.com/egeloen/IvoryGoogleMapBundle/blob/master/Resources/doc/usage/services/business_account.md