Upload image to Facebook Wall / Feed via Graph API

Thom Seddon picture Thom Seddon · Jun 5, 2012 · Viewed 11.2k times · Source

I am trying to upload local images directly to a pages feed (i.e. "Wall Photos" album).

This is the code that I think should work:

<?php
$facebook = new Facebook(array(
    'appId'  => $the_app_id,
    'secret' => $this_app_secret,
));
$facebook->setAccessToken($the_access_token);
$facebook->setFileUploadSupport(true);

$attachment = array(
    'message' => $the_post_body,
    'name' => $this_image_name,
    'picture' => '@' . $the_absolute_path_to_image
);

$result = $facebook->api('/me/feed, 'post', $attachment);

But this code just yields a plain text wall post with the contents of "message" (i.e. picture field is seemingly ignored). I have also tried "/page_id/feed", same result.

Now, simply changing the endpoint to "/me/photos", does upload the photo to a 'normal' album with the name of the app, but I want it to look as much like a normal post as possible and so hence into the "Wall Photos" album).

I realise that I could achieve this by querying the graph with FQL to find the object_id of the "Wall Photos" album, but if it does not exist it would require extra permissions to create it and I would rather keep permissions as simple as possible.

If anyone could point out how to upload photos to "/me/feed" I would greatly appreciate it.

Answer

Venu picture Venu · Jun 5, 2012

But this code just yields a plain text wall post with the contents of "message" (i.e. picture field is seemingly ignored). I have also tried "/page_id/feed", same result.

You can only give the link to picture but not the data.

Now, simply changing the endpoint to "/me/photos", does upload the photo to a 'normal' album with the name of the app, but I want it to look as much like a normal post as possible and so hence into the "Wall Photos" album).

Ye, it creates an album by default based on app. if already exists, it uploads to album. And generates a post.

I realise that I could achieve this by querying the graph with FQL to find the object_id of the "Wall Photos" album, but if it does not exist it would require extra permissions to create it and I would rather keep permissions as simple as possible.

You cannot upload to fb for me/feed end point. You should store in your server/s3/some service and give the public url to me/feed params.