1

I have a problem regarding the Facebook API. I've created an application "Screenshot Submission", from the concept of submitting the screenshot, the scenario is:

  1. After the users allows my application.
  2. The user will select a file to upload on the application using form then submit it.
  3. I want to upload the selected file(image/photo) to his/her album(auto generated from application) and post the file(image/photo) to his/her wall.

    $photo_details = array('message'=>$_REQUEST['arttitle'],'source'=> '@' . realpath($_FILES[file]tmp_name]));
    
    $facebook->api('/me/photos','POST',$photo_details);
    

The above code will upload photo to the autogenerated album, and returns an array like:

Array([id]=1234567890)

Now, how can post the uploaded file(image/photo) to his/her wall using php.sdk and graph api.

Any help would be appreciated. Thanks.

ifaour
  • 37,558
  • 12
  • 70
  • 79
Trez
  • 1,002
  • 5
  • 15
  • 23
  • Your code *in theory* suppose you actually setting the `source` parameter correctly, should post a feed to the user wall too.. – ifaour Mar 14 '11 at 13:11
  • the code is working because the image is uploaded to the album of the user but in pending mode. No feed/post in the user wall. – Trez Mar 15 '11 at 06:16
  • its working now...thanks. Anyway @ifaour what are the parameters allowed using the $facebook->api('/me/photos','POST',$photo_details) aside from 'message' and 'source'? – Trez Mar 16 '11 at 02:56
  • [here](http://developers.facebook.com/docs/reference/api/photo/) is the full list of parameters – ifaour Mar 16 '11 at 08:06

2 Answers2

4

First take the extended permission of publish_stream. Then the following code will help to upload the photo to wall

$attachment = array(
     'message' => 'The message that you want to display with picture',
     'name' =>'Your Application Name',
     'caption' => "Caption Under the picture",
     'link' => 'http://apps.facebook.com/yourapplication/',
     'description' => 'Some description with picture about picture or your application',
     'picture' => 'http://www.yoursite.com/somefolder/images/'.$Picturetoupload,
     'method'=>'stream.publish',
     'actions' => array(
                     array(
                        'name' => 'Your Application Name',
                        'link' => 'http://apps.facebook.com/Yourapplicationlink/'
                     )
                  )
     );
$uid=$fbme['id'];  // id of the user 
$result = $facebook->api('/'.$uid.'/feed/','post',$attachment);
Mariusz Jamro
  • 27,234
  • 22
  • 104
  • 144
Awais Qarni
  • 14,876
  • 22
  • 72
  • 134
  • thanks for this wonderful reply, one thing is that how would i know the picture link of the uploaded photo of the user. I dont't want to upload the photo in my server. – Trez Mar 15 '11 at 01:44
  • $pictureupload in from of picture is having that link – Awais Qarni Mar 15 '11 at 04:48
  • you're right, but i have problem on how to get the URL of the uploaded image in the facebook album of the user as what i've stated above. – Trez Mar 15 '11 at 07:59
  • 1
    take the extended permission of user_photos and query to photo table to get all information about photos. – Awais Qarni Mar 15 '11 at 09:27
  • got the solution by requesting an extended permission 'publish_stream' upon application authentication. Thank you. – Trez Mar 16 '11 at 02:54
0

After uploading the photo, you will get the "object_id of the photo" in return.

Make a post to facebook wall with "object_attachment = 'object_id of the photo'"

curl -F \ "access_token=..." \ -F "message=blah blah...." -F "object_attachment=object_id of the photo" \ "https://graph.facebook.com/me/feed

more info in http://developers.facebook.com/docs/reference/api/user/ posts section.

object_attachment:Facebook ID for an existing picture in the User's photo albums to use as the thumbnail image. The User must be the owner of the photo, and the photo cannot be part of a message attachment.

Devaroop
  • 7,315
  • 2
  • 33
  • 33