- Home /
"REQUEST_DENIED" with Google Places API
Hello Everyone!
I am trying to use google places api in my unity project and followed all the steps mentioned here. Following is my C# code,
#define ANDROID
using UnityEngine;
using System.Collections;
using System.Timers;
using SimpleJSON;
public class Places : MonoBehaviour
{
static int Neversleep;
LocationInfo currentGPSPosition;
string gpsString;
public GUIStyle locStyle;
int wait;
float radarRadius;
string radarType, APIkey, radarSensor;
string googleRespStr;
void Start ()
{
Screen.sleepTimeout = SleepTimeout.NeverSleep;
radarRadius = 1000f;
radarType = "restaurant";
APIkey = "MyAPIkey";
radarSensor = "false";
}
void RetrieveGPSData()
{
currentGPSPosition = Input.location.lastData;
gpsString = "Lat: " + currentGPSPosition.latitude + " Lon: " + currentGPSPosition.longitude + " Alt: " + currentGPSPosition.altitude +
" HorAcc: " + Input.location.lastData.horizontalAccuracy + " VerAcc: " + Input.location.lastData.verticalAccuracy + " TS: " + Input.location.lastData.timestamp;
}
void OnGUI ()
{
GUI.Box (ScaleRect.scaledRect(25,25,700,100), "");
GUI.Label (ScaleRect.scaledRect(35,25,700,100), gpsString, locStyle);
GUI.Box (ScaleRect.scaledRect(25,130,700,800), "");
GUI.Label (ScaleRect.scaledRect(35,135,700,800), "" +googleRespStr, locStyle);
#if PC
Debug.Log("On PC / Don't have GPS");
#elif !PC
Input.location.Start(10f,1f);
int wait = 1000;
if(Input.location.isEnabledByUser)
{
while(Input.location.status == LocationServiceStatus.Initializing && wait>0)
{
wait--;
}
if (Input.location.status == LocationServiceStatus.Failed)
{}
else
{
RetrieveGPSData();
StartCoroutine(Radar());
}
}
else
{
GameObject.Find("gps_debug_text").guiText.text = "GPS not available";
}
#endif
}
IEnumerator Radar ()
{
string radarURL = "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=" + currentGPSPosition.latitude + "," + currentGPSPosition.longitude + "&radius=" + radarRadius + "&types=" + radarType + "&sensor=false" + radarSensor + "&key=" + APIkey;
WWW googleResp = new WWW(radarURL);
yield return googleResp;
googleRespStr = googleResp.text;
print (googleRespStr);
}
}
I am getting correct latitude and longitude coordinates but for place, all I get is this,
{
"debug_info" : [],
"html_attributions" : [],
"results" : [],
"status" : "REQUEST_DENIED"
}
Has anyone used places api in their unity project? It would be great if someone could give me some hint.
Thanks in advance!
Merry Christmas & Happy New Year!
Answer by jainam · Jan 09, 2014 at 05:03 AM
got it working. turns out, if you leave the SHA-1 fingerprint field empty, then also google create API key which can be used in the app.
Hi was looking what you have done trying to recreate it myself. I was getting the same error you were but $$anonymous$$us the first line "debug_info". I tried it firs with a SHA fingerprint in the google api console place using mykey and then again with a new key without a fingerprint both to no success. Have you any other info regards to pitfalls or something else i may have over looked?
that's strange.... just want to make sure, by "without a fingerprint" you mean, you left the entire field empty, right? not even the package name (com.company.product)? while creating the API key, which option did you select from Server key, Browser key, Android key and iOS key? I had created a key for Android and it worked well. After reading your comment, I created a new key for iOS and browser also and they both worked well. Could you mention all the steps you followed?
Ok so previously not even the test links were working in the browser but they seem to be working now. Still no luck on device though. Is there anything aditional in terms of code or in your project beyond what you have shown and the SimpleJson script?
Went through the google console ticking on the apis i wanted to use, in this case i only wanted the places api. Generated a new key for android, leaving the field blank. And then was working between your code and the steps you had linked.
I left the entire field blank yes and had created a Android key which now works int he browser but cant get it working on device. I was just following the link you had included and parts of the code you had posted but with some alterations to display and when it was called etc
nope.....there is nothing additional in my code. this is really strange that you Android key is working on the browser but not on the device. if you could send your project, I could have a look and tell you.
I was giving it one last look over this morning before packing it up to send to you and i discovered what the problem was. In the URL that i had took from your code above it was had '"radarSensor=false"+radar sensor'. So the url on the device was reading as sensor=falsefalse. removed that and its now working on device.
Excellent i can now start playing with the results i can get. Thanks loads for the help. Is really appreciated. Am relatively new to the unity forums so i would up-vote if i knew how
Thanks again