简体   繁体   English

如何将用户照片从FB上传到我的网站

[英]How to upload user photos from FB to my site

I want give the option to user to be able to upload their photos from FB account in my drupal site.. 我想让用户可以从我的drupal网站的FB帐户上传他们的照片。

Are there any drupal modules to do it? 是否有任何drupal模块可以做到? I have heard of Graph API but not able to use it.. 我听说过Graph API,但无法使用它。

Any suggestion would be greatly appreciated! 任何建议将不胜感激!

Here is the example of how to access Facebook photo albums on your PHP site. 这是如何在您的PHP网站上访问Facebook相册的示例。 Hope it can help you. 希望它能对您有所帮助。

<?php
    require_once 'library/facebook.php';
    try{
        $facebook = new Facebook(array(
                'appId' => $app_id,
                'secret' => $app_secret,
                'cookie' => true
        ));
        if(is_null($facebook->getUser()))
        {
                header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
                exit;
        }
        $me = $facebook->api('/me');
    }catch(Exception $e){
        echo $e->getMessage();
        echo '<p>Please try clearing your browser cookies or <a href="http://demos.frnzzz.com/fbAlbum/photos.php">click here</a>.</p>';
        die;
    }
?>
<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> 
        <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script> 
        <script type="text/javascript"> 
        $(document).ready(function() {
            $('.slideshow').cycle({
                fx: 'fade'
            });
        });
        </script> 
        <title>WebSPeaks.in | Access facebook Albums on your site using PHP</title>
    </head>
    <body>
<?php
    $albums = $facebook->api('/me/albums');

    $action = $_REQUEST['action'];

    $album_id = '';
    if(isset($action) && $action=='viewalbum'){ 
        $album_id = $_REQUEST['album_id'];
        $photos = $facebook->api("/{$album_id}/photos");
        ?>
        <div class="slideshow"> 
        <?php
        foreach($photos['data'] as $photo)
        {
            echo "<img src='{$photo['source']}' />";
        }
        ?>
        </div>
        <?php
    }

    $pageURL .= 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    echo '<div class="alb">';
    if(strstr($pageURL,'.php?')){
        $and = '&';
    }else{
        $and = '?';
    }

    echo '<p class="hd">My Albums</p>';
    foreach($albums['data'] as $album)
    {
        if($album_id == $album['id']){
            $name = '<b><u>'.$album['name'].'</u></b>';
        }else{
            $name = $album['name'];
        }
        echo '<p>'."<a href=".$pageURL.$and."action=viewalbum&album_id=".$album['id'].">".$name.'</a></p>';
    }
    echo '</div>';
    ?>
    </body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM