REQUEST_DENIED in responce of Google Places API Request (sensor=true)

穿精又带淫゛_ 提交于 2019-12-01 21:46:49

问题


I am trying to get places around my location, using Google Places API.

Following is the code, for hitting URL for places search.

NSString *URL = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&sensor=true&key=0dp-j3dkCU_YUb97RHcbL5shmRrJ5R2y4bYz1Vw"];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:URL]
                                                           cachePolicy: NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval: 4];
[request setValue:@"application/json" forHTTPHeaderField:@"accept"];
NSObject *id1 = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

Which gets me the following response, in JSON Format.

{
  "html_attributions" : [],
  "results" : [],
  "status" : "REQUEST_DENIED"
}

On Searching Google Places API, It says, incorrect sensor parameter value is general cause for "REQUEST_DENIED". But, In my case, I am providing that, too, correct.

Any Idea where am I going wrong ??

Again, the APIKey I am using is common for the App to be develope on Android, iPhone and BlackBerry. Is that Valid ? Or, Do I need another APIKey (Specific for my iPhone App)? So, Another question is, Can i use the same key on all three platforms ??


回答1:


I took your URL and substituted a key that I know works, and got the expected results. At first glance I am guessing either your copied/pasted your key incorrectly, or you have not enabled the Places API for the Project this key is associated with in the API Console.

It's important to note that each project can have different services enabled - and you must enable the Places API manually for each project you wish to use it with -- can you confirm it is enabled in the console and the key is copied accurately?




回答2:


This error message can also appear if you are missing required parameters.

For example, I just had a similar issue using the /autocomplete endpoint of the Places API.

Sending a request to https://maps.googleapis.com/maps/api/place/autocomplete/json?key=XXXXXXXXXXXXXXXXXX&input=San, I was getting a response like this:

{
   "predictions" : [],
   "status" : "REQUEST_DENIED"
}

Even though it looks like a permissions issue (at least to me), it turns out I was simply missing a required sensor parameter.



来源:https://stackoverflow.com/questions/8833085/request-denied-in-responce-of-google-places-api-request-sensor-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!