Jump to content

Script for uploading imagwe on Facebook


radiations3

Recommended Posts

kindly check the following code i am trying to make such an script that'll allow you to upload images on facebook from your site

 

i am running this script locally but getting different errors like

 

Facebook.php is being downloaded from facebook api's

 

(Kindly provide any other working example that would be fine with me too i just need the functionality)

Warning: Missing argument 2 for Facebook::__construct(), called in C:\Users\Administrator\Desktop\face\abc.php on line 16 and defined in C:\Users\Administrator\Desktop\face\library\facebook.php on line 64

 

Notice: Undefined variable: secret in C:\Users\Administrator\Desktop\face\library\facebook.php on line 66

 

Notice: Undefined variable: secret in C:\Users\Administrator\Desktop\face\library\facebook.php on line 68

 

Fatal error: Call to undefined method Facebook::api() in C:\Users\Administrator\Desktop\face\abc.php on line 31

 

 

<html>
<head>
<title> Upload images to Facebook</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>
<?php
$app_id = 332267477347;
$app_secret = "989b7e58b48f17b3463ee54ea9c4f88d";
require_once 'library/facebook.php';
$facebook = new Facebook(array(
'appId'  => $app_id,
'secret' => $app_secret,
'fileUpload' => true
));


//It can be found at https://developers.facebook.com/tools/access_token/
$access_token = 'I pout here the key of my profile';

$params = array('access_token' => $access_token);

//The id of the fanpage
$fanpage = '194458563914948';

//The id of the album
$album_id ='406221796071956';

//Replace arvind07 with your Facebook ID
$accounts = $facebook->api('/faizan.gemeni/accounts', 'GET', $params);

foreach($accounts['data'] as $account) {
if( $account['id'] == $fanpage || $account['name'] == $fanpage ){
  $fanpage_token = $account['access_token'];
}
}


$valid_files = array('image/jpeg', 'image/png', 'image/gif');

if(isset($_FILES) && !empty($_FILES)){
if( !in_array($_FILES['pic']['type'], $valid_files ) ){
  echo 'Only jpg, png and gif image types are supported!';
}else{
  #Upload photo here
  $img = realpath($_FILES["pic"]["tmp_name"]);

  $args = array(
   'message' => 'This photo was uploaded via WebSpeaks.in',
   'image' => '@' . $img,
   'aid' => $album_id,
   'no_story' => 1,
   'access_token' => $fanpage_token
  );

  $photo = $facebook->api($album_id . '/photos', 'post', $args);
  if( is_array( $photo ) && !empty( $photo['id'] ) ){
   echo '<p><a target="_blank" href="http://www.facebook.com/photo.php?fbid='.$photo['id'].'">Click here to watch this photo on Facebook.</a></p>';
  }
}
}

?>
<!-- Form for uploading the photo -->
<div >
  <p>Select a photo to upload on Facebook Fan Page</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
  <p>Select the image: <input type="file" name="pic" /></p>
  <p><input class="post_but" type="submit" value="Upload to my album" /></p>
  </form>
</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.