PHP:Google Places API返回REQUEST_DENIED [英] PHP: Google Places API return REQUEST_DENIED

查看:62
本文介绍了PHP:Google Places API返回REQUEST_DENIED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google地方信息API添加位置时,我收到"REQUEST_DENIED".我已经搜索了上一个主题,因此我可以肯定该密钥是正确的,因为它可以用于Google地方信息搜索.

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.

可能与我的编码有关?这是我的PHP编码:

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;
                }

推荐答案

根据Google API控制台帮助,"Android和iOS密钥仅受某些API支持,例如Google Maps Android API或Google Maps SDK for iOS."( https://developers.google.com/console/help/).您可以在此处找到详细信息

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

就我而言,通过使用用于Bowser应用程序的密钥"而不是使用android/iOs密钥解决了问题.

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

这篇关于PHP:Google Places API返回REQUEST_DENIED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆