我想通过Google Maps API(V3?)从经度和纬度获取国家,地区和城市名称 - 使用PHP.我只是无法为每个县获得它,我设法得到这个代码,但它不适用于其他县,因为返回的结果是不同的(唯一正确的信息是国家,但即使是以本地名称返回而不是英文名):
<?
$lok1 = $_REQUEST['lok1'];
$lok2 = $_REQUEST['lok2'];
$url = 'http://maps.google.com/maps/geo?q='.$lok2.','.$lok1.'&output=json';
$data = @file_get_contents($url);
$jsondata = json_decode($data,true);
if(is_array($jsondata )&& $jsondata ['Status']['code']==200)
{
$addr = $jsondata ['Placemark'][0]['AddressDetails']['Country']['CountryName'];
$addr2 = $jsondata ['Placemark'][0]['AddressDetails']['Country']['Locality']['LocalityName'];
$addr3 = $jsondata ['Placemark'][0]['AddressDetails']['Country']['Locality']['DependentLocality']['DependentLocalityName'];
}
echo "Country: " . $addr . " | Region: " . $addr2 . " | City: " . $addr3;
?>
Run Code Online (Sandbox Code Playgroud)
这非常适合从我的国家获得正确的数据,但不适用于其他人......
我正在尝试向我的一个用户发送通知(https://developers.facebook.com/docs/app_notifications/),但我无法使用我的PHP SDK来完成这项工作.
我正在使用此代码:
$data = array(
'href'=> 'https://apps.facebook.com/MY_APP/',
'access_token'=> $app_token,
'template'=> 'test'
);
$sendnotification = $facebook->api('/USER_ID/notifications', 'post', $data);
Run Code Online (Sandbox Code Playgroud)
这就是我得到的错误:
致命错误:未捕获OAuthException:无效的OAuth访问令牌签名.在1039行的/usr/home/test/base_facebook.php中引发
这就是我获取应用访问令牌的方式:
$APPLICATION_ID = "MY_APP_ID";
$APPLICATION_SECRET = "MY_APP_SECRET";
$token_url = "https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $APPLICATION_ID .
"&client_secret=" . $APPLICATION_SECRET .
"&grant_type=client_credentials";
$app_token = file_get_contents($token_url);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
access_token存在问题,如果我在sode中直接使用访问令牌,它现在可以正常工作.
'access_token'=> 'K3Rds2y0cGm...',
Run Code Online (Sandbox Code Playgroud)
有谁知道应用程序访问令牌持续多长时间?