PHP: Google Places API return REQUEST_DENIED

爷,独闯天下 提交于 2019-12-11 19:14:10

问题


I am getting "REQUEST_DENIED" when using Google places API to add a place. I had searched previous thread and I am pretty sure the key is correct, as it can be used for Google Places Search.

Probably it's something to do with my coding? Here is my PHP coding:

                $jsonpost = '{
                  "location": {
                    "lat": ' .$coordinate[0] .',
                    "lng": ' .$coordinate[1] . '
                   },
                  "accuracy": 50,
                   "name": ' . $locator_name .'",
                   "types": ["other"],
                  "language": "en"
                }';

                $url = "https://maps.googleapis.com/maps/api/place/add/json?sensor=true&key=AIzaSyCj9yH5x6_5_Om8ebAO2pBlaqJZB-TIViY";
                $results = json_decode(ProcessCurl ($url, $jsonpost), TRUE);

                echo "<script>alert('Google Places submission returned " . $results["status"] ."');</script><br />";

                function ProcessCurl($URL, $fieldString){ //Initiate Curl request and send back the result
                    $ch = curl_init($URL);
                    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldString);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                  
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                    curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
                    curl_setopt($ch, CURLOPT_POST, 1); 
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
                        'Content-Type: application/json',                                                                                
                        'Content-Length: ' . strlen($fieldString))                                                                       
                    );                                                                      

                    $result = curl_exec($ch);
                    if (curl_errno($ch)) {
                        print curl_error($ch);
                    } else {
                        curl_close($ch);
                    }
                    return $result;
                }

回答1:


As per Google API console help "Android and iOS keys are only supported by some APIs, such as the Google Maps Android API or the Google Maps SDK for iOS." (https://developers.google.com/console/help/). you can find details here

In my case problem solved by using the 'key for bowser apps' instead of using android/iOs keys.



来源:https://stackoverflow.com/questions/20050115/php-google-places-api-return-request-denied

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