为什么我无法获得Facebook相册ID? [英] Why I cannot get the facebook album ID ?

查看:117
本文介绍了为什么我无法获得Facebook相册ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是在Facebook上创建专辑并将照片上传到该专辑,现在可以在Facebook上创建一个专辑,但是无法将照片上传到相册,我不知道为什么我无法获得相册ID ,任何解决方案或想法?

What I want to do is create album on facebook and upload photo to the album, now it work to create an album on facebook,but it's not work on uploading photo to album, I dont know why I cannot get the album ID, any solution or idea?

这里是我的代码,它是在Facebook上创建相册和上传照片

here is my code which is create album and upload photo on 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);
    ?>

谢谢

推荐答案

我不认为你可以从网址上传文件,尝试:

I dont think you could upload file from url, try:



$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相册ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆