Android Question Google Places API... Why doesn't my request work

Brian Robinson

Active Member
Licensed User
Longtime User
HI All,

Has anyone used the Google Places API to do text searches, and if so, can you please help me with how to get the API Key to work. The code I am using is as follows.

I have created the API Key through the developer console and switched on the Places API.

I have tried with multiple keys but the one I believe should work is a Browser based key. It is not linked to any referrers, so should work. I have tried it on the browser on my desktop and phone and the request works. The one thing I am not 100% sure on is the format of the POST request. Can anyone see any problems with what I have there? I am trying to use SandroProxy to intercept the calls and see if I am missing something but am getting other problems there around the ssl certificate.

B4X:
Public Sub GetPlaces
    Dim Job As HttpJob  
    Dim iDistance As Int = 1
  
    Dim url As String = "https://maps.googleapis.com/maps/api/place/textsearch/json"
    Dim query As String = "?query=French+restaurants&Location=" & currLat & "," & currLng & "&radius=1000m&types=food&key=" & Constants.GOOGLE_PLACES_WEB_API_KEY

    Log(url&query)
    Job.Initialize("GetEateries", Me)
    Job.PostString(url,query)
'  
    Job.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36")
      Job.GetRequest.SetContentType("application/x-www-form-urlencoded")  
End Sub

The error I am getting is in the Job.GetString:
{
"error_message" : "An internal error was found for this API project.",
"html_attributions" : [],
"results" : [],
"status" : "REQUEST_DENIED"
}

Any help greatly appreciated...
 

Brian Robinson

Active Member
Licensed User
Longtime User
Awesome!!!! That did the trick Erel.

Thanks for your help. I guess the problem is the other app I have been working on which also gets data from a web service is not written correctly using all POST actions rather than GET when returning values (This is what I thought was the correct way anyway??? Happy to be given an explanation as to why I might be wrong).

Anyways... Now I can continue on, so thank you very much.

Regards
Brian
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…