2012-01-09 4 views
0

내가하고 싶은 일은 페이스 북에 앨범을 만들고 앨범에 사진을 업로드하는 것입니다. 이제 페이스 북에 앨범을 만들 수 있지만 사진을 앨범에 업로드 할 수 없습니다. 앨범 ID를 얻을 수없는 이유는 모르겠지만, 어떤 해결책이나 아이디어? 여기 왜 Facebook 앨범 ID를 가져올 수 없습니까?

<?//At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line: 
    $facebook->setFileUploadSupport(true); 

    //Create an album 
    $album_details = array(
      'message'=> 'name', 
      'name'=> 'name' 
    ); 
    $create_album = $facebook->api('/me/albums', 'post', $album_details); 

    //Get album ID of the album you've just created 
    $albums = $facebook->api('/me/albums'); 
    foreach ($albums["data"] as $album) { 
    //Test if the current album name is the one that has just been created 
     if($album["name"] == 'name'){ 
      $album_uid = $album["id"]; 
     } 
    } 

    //Upload a photo to album of ID... 
    $photo_details = array(
     'message'=> 'test' 
    ); 
    $file='http://scm-l3.technorati.com/11/12/30/59287/google-logo-682-571408a.jpg'; //Example image file 
    $photo_details['image'] = '@' . realpath($file); 

    $upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details); 
    //print_r($upload_photo); 
    ?> 

감사

을 앨범을 만들고 페이스 북에 사진을 업로드 내 코드입니다
+0

문제입니다 ..? –

+0

나는 album_id를 얻습니다. 문제는 지금 앨범 – Oscar

답변

1
난 당신이 URL에서 파일을 업로드 할 수 있다고 생각하지 말아

는 시도 :

 

$pathToFile = "/some/path/someimage.jpg"; 
$facebook->setFileUploadSupport(true); 
............ 
$create_album = $facebook->api('/me/albums', 'post', $album_details); 
//get the album id 
$album_uid = $create_album["id"]; // no need for foreach loop 

..... 
$args = array('message' => 'Some message'); 
$args['image'] = '@' . realpath($pathToFile); //see realpath use here 

$data = $facebook->api('/'. $album_uid . '/photos', 'post', $args); 

 

그것을 희망 도움이

+0

에 답장을 보내 주셔서 감사합니다. 내 경로를 변경하고 코드를 시험해 보았습니다. 이미지를 업로드 할 수 없으며, var_dump 내 $ album_uid를 가지고 있습니다. 지금은 잘 모르겠습니다. 내 앨범에 업로드되지 않는 이유 – Oscar

0

당신은 http 파일에 대해 realpath을 부를 수 없습니다. 로컬 파일에만 사용됩니다. curl, wget 또는 file_get_contents/file_put_contents과 같은 PHP 내부 함수 중 하나를 사용하여 파일을 다운로드하십시오. 예를 들어

: 앨범 album_uid 또는 이미지 업로드가

$file='http://scm-l3.technorati.com/11/12/30/59287/google-logo-682-571408a.jpg'; //Example image file 
$output = tempnam(sys_get_temp_dir(), 'blex_'); 
$cmd = "wget -q \"$file\" -O $output"; 
exec($cmd); 
$photo_details['image'] = '@' . realpath($output); 
관련 문제