Post Image on friends facebook wall

In this post we shall learn how to post image data on facebook friends wall.

In my last series of facebook i have explained how to post some text data on your friends wall, well posting an image on your friends wall is the similar with just one minute change.

Note: Remember one thing image is a file and if you want to post a file on your friends wall then in that case you have to make use of a class named "FBGraphFile".

You may read my previous blog on posting text data on friends wall and in case of you want to post an image on your friends wall then you have to update the function to the code given below


- (IBAction)postImageButtonclicked:(id)sender
{
    if (fbgraphref!=nil
    {
        NSMutableDictionary *variables = [[NSMutableDictionary alloc]initWithCapacity:2];
      
        
        FbGraphFile *fbfile = [[FbGraphFile alloc]initWithImage:imgv.image];
        
          [variables setObject:fbfile forKey:@"file"];
          [variables setObject:@"iPhone by radix" forKey:@"message"];
        
        [fbgraphref doGraphPost:[NSString stringWithFormat:@"%@/photos",self.friendID] withPostVars:variables];
        
        UIAlertView *objAlert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Data Posted on friends wall" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [objAlert show];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

Code Explanation: In the above code i am using the class FBGraphFile and storing the image data that i want to send to my friends wall.

Then with the help of dictionary i am encapsulating the image and some text about the image.

Later with the help of the FBGraph object i am posting the image and the text data regarding that image  with the help of the method named doGraphPost also make a note that this time its not the feeds that i am using its the photo variable since we want to push a photo on our friends wall.

Now when everything is in place you may run the application.




Now select a friend from the list and when you do you will be navigated to the following screen.


Now when you tap on the Post Image button then the image which is currently selected by you will be posted on your friends facebook feeds.




Later you may login to your facebook account and check your friends wall just in case to see if the image is loaded or not



You can download the source file from here.

If you have any queries regarding this post that you want to ask me let me know via comments or mails

Until then Happy iCoding and have a great Day.

Comments

Post a Comment