Uploading pictures on facebook and website
I'm starting to learn the API to see what is available.
Is there a way for users to upload picture and have them both on facebook and on a site?
Ex: If I create a website for bird watching www.birdwatch.com, is there a way for people to post picture so that it will appears in their prof开发者_StackOverflowile and on the website at the same time?
And when people comment on the picture it will appear on both the website and facebook?
Yes but its fairly involved stuff. You'll need to get an FB developer token, code some HTML and PHP stuff etc.
Here is some PHP code that I use to take files that have been uploaded to my server then throw 5 of them up on Facebook follows by a 6th photo that is a graphic that says "Click the link in the album description to see more".
The following code is very much from the Botchit & Scarper Web Dev college, but it should highlight how to get things going :)
[code]
// Facebook Shite
$fb_app_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';
$fb_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$fb_app_url = 'http://apps.facebook.com/your-fb-page/canvas-name-here';
require './facebook.php';
//Create facebook application instance.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret
));
///////////////////////////////////////////////////
$facebookalbumname = stripslashes($_POST['facebookalbumname']);
$facebookalbumurl = stripslashes($_POST['facebookalbumurl']);
$facebookphoto1 = stripslashes($_POST['facebookphoto1']);
$facebookphoto2 = stripslashes($_POST['facebookphoto2']);
$facebookphoto3 = stripslashes($_POST['facebookphoto3']);
$facebookphoto4 = stripslashes($_POST['facebookphoto4']);
$facebookphoto5 = stripslashes($_POST['facebookphoto5']);
///////////////////////////////////////////////////
//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(
'access_token'=> 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'message'=> "See ALL the photos in this gallery at $facebookalbumurl ." ,
'name'=> $facebookalbumname
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
///////////////////////
$current = file_get_contents($facebookphoto1); file_put_contents("facebookphoto1.jpg", $current);
$current = file_get_contents($facebookphoto2); file_put_contents("facebookphoto2.jpg", $current);
$current = file_get_contents($facebookphoto3); file_put_contents("facebookphoto3.jpg", $current);
$current = file_get_contents($facebookphoto4); file_put_contents("facebookphoto4.jpg", $current);
$current = file_get_contents($facebookphoto5); file_put_contents("facebookphoto5.jpg", $current);
///
//Upload a photo to album of ID...
$photo_details = array(
'access_token'=> 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'message'=> "See ALL the photos in this gallery at $facebookalbumurl 1"
);
$photo_details['image'] = '@' . realpath('facebookphoto1.jpg');
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
///
//Upload a photo to album of ID...
$photo_details = array(
'access_token'=> 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'message'=> "See ALL the photos in this gallery at $facebookalbumurl 2"
);
$photo_details['image'] = '@' . realpath('facebookphoto2.jpg');
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
///
//Upload a photo to album of ID...
$photo_details = array(
'access_token'=> 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'message'=> "See ALL the photos in this gallery at $facebookalbumurl 3"
);
$photo_details['image'] = '@' . realpath('facebookphoto3.jpg');
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
///
//Upload a photo to album of ID...
$photo_details = array(
'access_token'=> 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'message'=> "See ALL the photos in this gallery at $facebookalbumurl 4"
);
$photo_details['image'] = '@' . realpath('facebookphoto4.jpg');
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
///
//Upload a photo to album of ID...
$photo_details = array(
'access_token'=> 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'message'=> "See ALL the photos in this gallery at $facebookalbumurl 5"
);
$photo_details['image'] = '@' . realpath('facebookphoto5.jpg');
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
///
//Upload a photo to album of ID...
$photo_details = array(
'access_token'=> 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'message'=> "See ALL the photos in this gallery at $facebookalbumurl 6"
);
$photo_details['image'] = '@' . realpath('seeallthephotos.jpg');
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
?> [/code]
精彩评论