2013-11-26 2 views
1

사진을 개인 플리커 계정에 직접 업로드하는 사진 업 로더를 만드는 중입니다 ... 지금 내 모든 사진 세트를 (제목별로) 호출하고 내 select 드롭 다운 목록을 채우려고합니다. 그들. 불행히도 제가 시도한 모든 것은 효과가 없습니다 ... 그래서 저는 여러분에게 경험있는 사람들로부터 도움을 청합니다!(해결) "선택"양식을 flickr photoset 제목으로 채우는 방법? (PHP 사용)

<select class="categorize-options"> 

<?php 
    require_once('class.flickr.php'); 

    $flickr = new Flickr('api key', 'api shared secret'); 
    $results = $flickr->getPhotosets(); 

    if (!empty($results)): 
     foreach($results as $photoset):?> 

      <option><?php echo $photoset['title']; ?></option> 

     <?php endforeach; 
    else: 

     echo "This isn't working!!! :)"; 
    endif; 
?> 
</select> 

: 내 파일의 코드 내 주 문서 내에서 getPhotosets 메소드를 호출하는 데 사용되는 class.flickr.php

// Code being used for the purpose of calling photoset titles 
public function getPhotosets() { 

    // Function specific variables 
    $flickr_api_call  = "http://api.flickr.com/services/rest/"; 
    $method     = "flickr.photosets.getList"; 
    $nsid     = 'my user id'; 

    $url_parameters = array(
     'method'    =>$method, 
     'oauth_consumer_key' =>$this->flickr_key, 
     'user_id'    =>$nsid, 
     'format'    =>$this->format, 
     'nojsoncallback'  =>'1', 
     'oauth_nonce'   =>$this->nonce, 
     'oauth_timestamp'  =>$this->timestamp, 
     'oauth_version'   =>'1.0',  
    ); 

    $parameters_string = ""; 

    foreach ($url_parameters as $key=>$value) $parameters_string .= "$key=" . urlencode($value) . "&"; 

    $url = $flickr_api_call . "?" . $parameters_string; 

    $photosets = array(); 
    $data = json_decode(file_get_contents($url), true); 

    if ($data['stat'] != 'fail') { 

     $photosets = $data['photosets']['photoset']; 
     return $photosets; 
    } else { 

     return false; 
    } 

    var_dump($photosets); 
} // end getPhotosets 

이라고에서 :)

여기에 내가 함께 일하고 있어요 코드입니다 실제로 나를 혼란스럽게하는 것은 var_dump()else 문장이 모두 표시되지 않고 있다는 것입니다. 경험 많은 의견을 얻으려면 큰 도움이 될 것입니다 ... 감사합니다!

답변

0

먼저, flickr 설명서에 따르면 방법 flickr.photosets.getList에 대한 승인이 필요 없다고하지만 ... 잘못되었습니다. 이 같은 인증 기능 뭔가를 실행해야합니다

// Get list of photosets (for their titles) 
public function getPhotosets() { 

    // Function specific variables 
    $flickr_api_call  = $this->flickr_rest_call; 
    $method     = "flickr.photosets.getList"; 
    $nsid     = 'user_id'; 
    $access_token   = "access_token"; 
    $access_token_secret = "access_token_secret"; 

    $url = "format=" . $this->format; 
    $url .= "&method=" . $method; 
    $url .= "&nojsoncallback=1"; 
    $url .= "&oauth_consumer_key=" . $this->flickr_key; 
    $url .= "&oauth_nonce=" . $this->nonce; 
    $url .= "&oauth_signature_method=" . $this->sig_method; 
    $url .= "&oauth_timestamp=" . $this->timestamp; 
    $url .= "&oauth_token=" . $access_token; 
    $url .= "&oauth_version=1.0"; 
    $url .= "&user_id=" . urlencode($nsid); 

    $baseurl   = "GET&" . urlencode($flickr_api_call) . "&" . urlencode($url); 
    $hashkey   = $this->flickr_secret . "&" . $access_token_secret; 
    $oauth_signature = base64_encode(hash_hmac('sha1', $baseurl, $hashkey, true)); 

    $url_parameters = array(
     'method'    =>$method, 
     'oauth_consumer_key' =>$this->flickr_key, 
     'user_id'    =>$nsid, 
     'format'    =>$this->format, 
     'nojsoncallback'  =>'1', 
     'oauth_nonce'   =>$this->nonce, 
     'oauth_timestamp'  =>$this->timestamp, 
     'oauth_signature_method'=>$this->sig_method, 
     'oauth_version'   =>'1.0', 
     'oauth_token'   =>$access_token, 
     'oauth_signature'  =>$oauth_signature 
    ); 

    /* Now that we have encoded the parameters for our ouath_signature 
    * and have reformated them for the url we need to send... we must 
    * re-urlencode them too. */ 

    $parameters_string = ""; 
    foreach ($url_parameters as $key=>$value) 
     $parameters_string .= "$key=" . urlencode($value) . "&"; 

    $url = $flickr_api_call . "?" . $parameters_string; 

참고 : 당신은 당신이 두 배 값을 urlencode 필요 nsid 사용하는 시간! 이유 : 둘째 %2540

를이에서 JSON 응답에서 호출을 변경 : 만이 %40처럼 돌아갑니다 일단 인코딩,하지만 유지하기 위해 경우 @% 당신은 두 번이 결과로 인코딩해야합니다 이것에 <option><?php echo $photoset['title']; ?></option> : <option><?php echo $photoset['title']['_content']; ?></option>

이것은 내가 이것을 성취 할 수 있었던 방법입니다. 더 좋은 방법이 있다면, 이것에 대해 듣고 싶습니다.