2017-10-06 28 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