I have an application in which i have to post image on Wall of facebook.
Now problem is i used GraphAPI facebook and i have to pass link of photo but i have photo in my iPhone and not on any server.
So how do i post wall with image and other parameters without URL of image?
You may use NSURLConnection ASIHttpRequest library for downloading the images from a url.
You will have to do the following:
1. Create a NSUrlConnection and implement the delegate methods
2. Pass the url in your request and you will get the data in -(void)connectionDidFinishLoading: (NSURLConnection *)connection
3. You can then create a UIImage from this data using UIImage *image = [[UIImage alloc] initWithData:activeDownloadData];
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = @"Enter your message:";
NSDictionary *params = nil;
[[FBRequest requestWithDelegate:self] call:@"facebook.photos.upload" params:params dataParam:(NSData*)wallImage];
[dialog show];
Try using BMSocialShare which is a simple lib I wrote. It is exactly doing what you want. Upload some local image (and even open a dialog for the user to add a comment) to the user's wall:
BMFacebookPost *post = [[BMFacebookPost alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
[[BMSocialShare sharedInstance] facebookPublish:post];
--
Actually, posting an image to the Facebook wall has to be from the web. So you will have to upload the image first; maybe try a 3rd party service like twitpic or something, return the response url and place it in your params.
--
You can use the following to post with image to Facebook. You can also replace UIImage
with a physical URL as well.
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppID, @"app_id",
@"http://bit.ly/dDZQXt", @"link",
@"www.has.to.be.web.based.com", @"picture",
EasyStrings(@"Mobile Profiles for ",device), @"name",
EasyStrings(@"Current Profile: ",currProfile), @"caption",
@"I am using Mobile Profiles for iPhone, iPod touch and iPad.", @"description",
message, @"message",
nil];
[_facebook dialog:@"feed"
andParams:params
andDelegate:self];
The house icon is loaded from [UIImage imageNamed:@"something.png"]
.
I modified the facebook demo app. It uses the modal view to select a picture from your phone. You can use this code, granted you must add two buttons (ie, selectPicture button and a uploadPhoto button) -- also be sure to add to UIViewController in the .h file:
/**
* Upload a photo.
*/
- (IBAction)uploadPhoto:(id)sender {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image, @"picture",
nil];
[_facebook requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
}
/**
* Select a photo.
*/
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction) selectPicture:(UIButton *)sender;
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.