Google Premier requires for you to generate a signature over the URL you’re going to ask for, then send that signature alongside the request. Here is how to do it, as there is no PHP example in the Google Premier URL Signature documentation
In this code snippet we assume:
$request_url
has the url that will be using the Google Premier service (for example, Static Maps API). It also already has the client param, sensor param, etc.$signature_key
has the key provided to you by Google- You are running this snippet from an authorized domain
- Props to ZZ Coder at StackOverflow
1 2 3 4 5 6 |
|
‘Strange’ things in this snippet:
- Why the strtr()? Because Google uses URL-Safe base64
- Why the true param at the end of hash_hmac? Because we need it the signature to be returned in binary before base64encondig it.
Then you just have to append $signature_param
to your original request (which
we’ve assumed is in $request_url
) to have a correctly signed Google Premier
request.