It is some time ago i wrote my last post facebook development and by that time many new articles have pop up on the uses of graph API.
In this post i will go through how to upload a photo thruogh your facebook app and later on how to tag it.
I think everyone has experienced some where an app which selects “top friends”, “best friends” etc etc and pops up an image with ourselves tagged. Honestly it can be sucha nuisance that you hate to see. If you log into facebook after some time,you might be wondering how you got tagged to soo many pics.
In this code i assume that you have prepared th image to be uploaded by doing all edits. If you have no clue on have to get images from facebook, you should look into CURL. And for editing GD.
First of all to publish an image the user need to provide “Publish Stream” permission during authentication stage. See my previous post on facebook application Authentication.
You can publish a photo to app users profile with a POST to graph API photos as below:
$facebook->api('/me/photos', 'POST', $image);
Before doing this in php SDK set file upload permissions as follows:
The $image is an array with photo details. ‘access_token’ should be provided to see whether a valid session is present. ‘message’ is the message or the desription that should be added to the image. I am using a variable $mess. ‘image’ should carry the path of the image to be uploaded.’@’.realpath($path); creates a curl-style upload path.
$image = array( 'access_token' => $session['access_token'], 'message' => $mess, ); $image['image'] = '@'.realpath($path);
Well thats it for image upload. Facebook will create an album with your app name if you dont provide with a album ID. Else you can upload the image to an already existing album using the album ID. Try is your self