3

I want to upload photo to one of the user's groups. Is it possible?

If it's not possible then is there any work-around for this?

Regards, Sanket

Sanket Sahu
  • 8,468
  • 10
  • 51
  • 65

1 Answers1

4

Facebook has decent documentation about uploading to a group. You can post a picture object to the group API

https://developers.facebook.com/docs/reference/api/group/

Make sure to read the above link and read the CREATE section, also any needed permissions, etc. You code using the latest php-sdk should look similar to this...

//IF FILE UPLOAD
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000)){
if ($_FILES["file"]["error"] > 0){
    $error .= "Return Code: " . $_FILES["file"]["error"] . "<br />";
}else{
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

$args = array('message' => $_GET['title']);
$args['image'] = '@' . realpath($_FILES["file"]["tmp_name"]);
$data = $facebook->api('/me/photos', 'post', $args);
$entry->details = $data['id'];
}
}

The important part is:

$data = $facebook->api('/me/photos', 'post', $args);

which uploads to the user, you can change this to post to a group something like this...

$data = $facebook->api('/GROUP_ID/photos', 'post', $args);
Sanket Sahu
  • 8,468
  • 10
  • 51
  • 65
Keith Connolly
  • 386
  • 2
  • 9
  • i tried this '/GROUP_ID/photos' but 'OAuthException: An unknown error has occurred.' is being returned. I have post a question regarding this on: http://stackoverflow.com/questions/19720592/oauthexception-when-trying-to-upload-post-photos-to-group. Please help me. – Messy Coder Nov 04 '13 at 05:50
  • Same for me! @MessyCoder . I'm also looking for a solution for last few days! – Aajahid Nov 06 '13 at 11:44
  • 1
    Can we upload image to group using facebook api? https://developers.facebook.com/docs/reference/api/group/#posts – Ari Dec 21 '13 at 05:58