mardi 18 décembre 2018

guzzle request wrong result with google maps api

I try send a google place api search with this command

 $client = new Client();
    $res = $client->request('GET', $url,[
        'query' => [
            'type' => 'gas_station',
            'query' => 'Uberlandia,MG',
            'key' => 'MYKEY',
        ],
    ]);

And this return a wrong result {"html_attributions":[],"results":[],"status":"ZERO_RESULTS"}

but this query is ok, if i try in postman or in browser this return results

https://maps.googleapis.com/maps/api/place/textsearch/json?type=gas_station&query=Uberlandia%2CMG&key=MYKEY

I have see a diference between the results using guzzle and the query from google

how i can solve this issue? or i'm doing something wrong?

I try use this way too

 $client = new Client();
    $res = $client->request('GET', $url,[
        'headers' => [
            'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
            'Accept'     => 'application/json',
            'cache-control'      => 'no-cache'
        ],
        'query' => [
            'type' => 'gas_station',
            'query' => 'Uberlandia,MG',
            'key' => 'MYKEY',
        ],
        'on_stats' => function (TransferStats $stats) use (&$url) {
            $url = $stats->getEffectiveUri();
        }
    ]);

but has the same result

this problem work with other querys too like

$url = "https://maps.googleapis.com/maps/api/place/textsearch/json";
$client = new Client();
$res    = $client->request('GET', $url, [
    'headers' => [
        'User-Agent'    => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
        'Accept'        => 'application/json',
        'Content-Type' => 'application/json',
        'cache-control' => 'no-cache',
    ],
    'query' => [
        'type' => 'gas_station',
        'keyword' => 'posto,combustiveis',
        'query' => 'lago sul - Shi Sul Qi 05 Área Militar Vi Comar, S/n Parte - Lago Sul, Brasília - DF, Brasil',
        'key' => 'MYKEY'
    ],
]);

and on browser or postman

https://maps.googleapis.com/maps/api/place/textsearch/json?type=gas_station&keyword=posto,combustiveis&query=lago+sul+-+Shi+Sul+Qi+05+%C3%81rea+Militar+Vi+Comar%2C+S%2Fn+Parte+-+Lago+Sul%2C+Bras%C3%ADlia+-+DF%2C+Brasil&key=MYKEY

best regards



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire