2012-01-09 7 views
0

私がしたいことは、Facebookにアルバムを作成してアルバムに写真をアップロードすることです。これでアルバムはFacebookに作成されますが、写真をアルバムにアップロードすることはできません。なぜアルバムIDを取得できないのか、任意の解決策またはアイデア?なぜFacebookのアルバムIDを取得できないのですか?

 

$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); 

 

はそれを願っています:ここ

は、アルバムを作成して、Facebookを利用して

<?//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

あなたの問題は、アルバムにalbum_uidや画像のアップロードですか..? –

+0

私はalbum_idを取得しました。問題は今アルバム – Oscar

答えて

1

を、写真をアップロードしている私のコードで私がしようと、あなたはURLからファイルをアップロードすることができると思ういけませんヘルプ

+0

への返信ありがとう、私は自分のパスを変更してコードを試しています、画像をアップロードできません、私は$ album_uidをvar_dumpしました。なぜ私のアルバムにアップロードされないのですか? – Oscar

0

httpファイルに対してrealpathを呼び出すことはできません。ローカルファイル専用です。 curlwget、またはfile_get_contents/file_put_contentsなどのPHP内部関数のいずれかを使用してファイルをダウンロードしてください。例えば

$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); 
関連する問題