2012-12-09 7 views
1

사용자 장소 데이터 (사용자 체크인 정보의 장소에 대한 세부 정보)를 가져 오려고합니다. 사용자 액세스 토큰을 사용하여 데이터를 가져 왔습니다. 이것은 내가 사용하고있는 코드입니다 :foursquare/user/self/checkins 데이터에서 장소 분석하기

if($_GET['code']){ 
$authkey = file_get_contents("https://foursquare.com/oauth2/access_token? client_id=".$client_id."&client_secret=".$secret."&grant_type=authorization_code&redirect_uri=".$redirect."&code=".$_GET['code']); 
$decoded_auth = json_decode($authkey,true); 
$venueinfo = file_get_contents("https://api.foursquare.com/v2/users/self/checkins?oauth_token=$access_token&v=$version"); 
$decoded_venueinfo = json_decode($venueinfo, true); 
foreach ($decoded_venueinfo->response->checkins->items->venue as $result){ 
    echo $result->name; 
     echo $result->id; 
     echo $result->location->address; 
     echo $result->location->city; 
     echo $result->location->country;  
    } 
} 

빈 페이지가 나타납니다. 에코 "오류"와 함께 첫 번째 "if"의 끝에 "else"를 추가하려고 시도했습니다. 그래서 "if"문 조건이 거짓이라고 추측합니다. 저는 PHP를 처음 접했고 배우로서 배웁니다. 어떤 도움을 주시면 감사하겠습니다.

답변

0

_GET [ 'code']은 요청 URL에서 "& code ="GET 매개 변수를 참조합니다. 이 매개 변수는 Foursquare가 앱을 인증하여 사용자를 인증하는 요청에 표시됩니다. 앱을 테스트하기 위해 수동으로 요청하는 것처럼 들리는데,이 경우 URL에 code 매개 변수를 입력해야합니다.

+0

감사합니다. 이제 파싱 문제가 있습니다. 사용자가 체크인 한 장소를 표시하려고합니다. 이것은 코드입니다 : $ decoded_venueinfo = json_decode ($ venueinfo, true); foreach ($ decoded_venueinfo-> response-> checkins-items-venue를 $ 장소로 사용) { $ name = $ venue-> name; \t $ id = $ venue-> id; echo "장소 이름 : $ name, Id : $ id"; } 작동하지 않습니다. 화면에 "어레이"가 인쇄됩니다. – user1889653