2017-10-06 60 views
-1

嗨Dears Friends我需要你的帮助。如何使用Php来使用或访问Web API?

我们如何使用php访问Web api? 我已经在做这样的,但是,CLIENT_ID它显示我的访问令牌错误,而我的Instagram的访问令牌是新鲜的还是没有过期和正确

<?php 
if(!empty($_GET['location'])){ 
    $maps_url='https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($_GET['lacation']); 
$maps_json = file_get_contents($maps_url); 
$maps_array=json_decode($maps_json,true); 
    $lat= $maps_array['result'][0]['geometry']['location']['lat']; 
    $lng = $maps_array['result'][0]['geometry']['location']['lng']; 
    $instagram_url = 'https://api.instagram.com/v1/media/search?lat='.$lat.'&lng'= .$lng. '&client_id=xxxxxxxxxxxxxxxxxx' 

$instagram_json = file_get_contents($instagram_url); 
    $instagram_array = json_decode($instagram_json,true); 

} 
?> 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
<title>WebApi_Learning</title> 
    </head> 
    <body> 
<form action=""> 
     <input type="text" name="location"/> 
    <button type="submit">Submit</button><br> 
    <?php 
    if(!empty($instagram_array)){ 
    foreach($instagram_array['data']as $image){ 
     echo '<img src='. $image['images']['low_resolution']['url'].'" alt="" />'; 
    } 
    } 
     ?> 
       </form> 


</body> 
</html> 

回答

0

我会写一个评论,但我可以因为misssing声誉点不是。 综观API,文档,API docs接受这些参数媒体/搜索方法: 纬度,经度,的access_token

你$ instagram_url完全忽略了的access_token,但提供的client_id代替这似乎并不成为了一个有效的输入参数媒体/搜索方法。

我的猜测是,你需要按照顺序检索的的access_token认证程序如下描述API docs

+0

哈利感谢您的帮助 – Zack