2

在此先感谢我正在尝试从 facebook 用户那里获取 facebook 相册:为此,我正在下载 sdk 代码并尝试使用此代码:- 我面临的问题是我只能根据我的 facebook 用户 ID 而不是其他用户 ID 来获取相册当我从其他 id 登录 facebook 时

<?php
   include 'fb-sdk/src/facebook.php';
   ini_set("display_errors",1);
   $config = array();
   $config['appId'] = "268995893218105";// 733175570042916  
   $config['secret'] = "051602de261868f4ab7a8b95dd556dcb";
   //8642b7e2a689fb059e8de1518e990593
   $config['fileUpload'] = true; // optional

   $facebook = new Facebook($config);
   $user_id =  $facebook->getUser();
   $access_token = $facebook->getAccessToken(); 
   ?>
  <html>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

        <!-- Just adding some style -->
        <style type='text/css'>
        body{
            font-family: "Proxima Nova Regular","Helvetica  Neue",Arial,Helvetica,sans-serif;
            font-size: 12px;
        }

        .fbAlbumImage, 
        .fbAlbum{
            float: left;
            height: 170px;
            padding: 10px; 
            width: 150px; 
        }
        </style>


<body><?php

if ($user_id && $access_token) {

    // We have a user ID, so probably a logged in user.
    // If not, we'll get an exception, which we handle below.
    try {

        $params = array(
            'method' => 'get',
            'access_token' => $access_token
        );

        if (isset($_GET['aid']) && $_GET['aid'] != '') {
            $aid = $_GET['aid'];
            $user_album_photos = $facebook->api('/' . $aid . '/photos', $params);
            //echo "Photos<br/>"; 
            ?>
  <div id="gallery">
            <?php foreach ($user_album_photos['data'] as $key => $value) {
                ?>
                    <div class="fbAlbumImage"> 
                     <input type="checkbox" id="fbimport_id<?php echo $value['id']; ?>" value="<?= $value['id'] . ',' . $value['images']['0']['source'] . ',' . $value['name'] ?>" name="fbimport[]" > <span>Import this Memory</span>               
                                    <a href="<?= $value['images']['0']['source'] ?>"><img src="<?= $value['images']['0']['source'] ?>" height="100" width="100" /></a>
                     <?php echo $value['name']; ?>
                    </div>
                <?php }
            ?></div>
        <?php
        } else {
            $user_albums = $facebook->api('/'.$user_id.'/albums', $params);
            echo '<h3 class="page-title">Select Your Facebook Album</h3><br/><br/>';
            foreach ($user_albums['data'] as $key => $value) {

                /* load album if not blank */
                if (isset($value['count']) && $value['count'] != '' && $value['count'] != NULL && $value['count'] > 0) {

                    /* check if album has a cover photo. if not than load a default image */
                    if (isset($value['cover_photo']) && $value['cover_photo'] != '' && $value['cover_photo'] != NULL) {
                        $user_album_cover = $facebook->api('/' . $value['cover_photo'], $params);
                        $album_thumbnail = $user_album_cover['images']['0']['source'];
                    } else {
                        $album_thumbnail = 'default_thumb.gif';
                    }
                    /* check if album has cover photo end */
                    ?>
                    <div class="fbAlbum">        
                                       <a href="?aid=<?= $value['id'] ?>" ><img src="<?= $album_thumbnail ?>" height="100" width="100" /></a>

                            <h3 id='bottomcaption'><?php echo $value['name']; ?></h3>

                    </div>

                    <?php
                }//if(isset($value['count']) && $value['count'] != '' && $value['count'] != NULL && $value['count']>0)
                /* load album if not blank end */
            }
        }
    } catch (FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl();
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
    }
} else {

    // No user, print a link for the user to login
    $login_url = $facebook->getLoginUrl();
    echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
<script type="text/javascript" src="jQuery-lightbox/js/jquery.js"></script>
<script type="text/javascript" src="jQuery-lightbox/js/jquery.lightbox-0.5.js"></script>
<link rel="stylesheet" type="text/css" href="jQuery-lightbox/css/jquery.lightbox-0.5.css" media="screen" />

<script type="text/javascript">
$(function() {
    $('#gallery a').lightBox();
});
</script>
</body>
</html>
4

1 回答 1

1

您可以从这里获得一些帮助:请查看 http://www.codeofaninja.com/2011/06/display-facebook-photos-to-your-website.html

于 2013-10-18T10:10:10.620 回答