Reputation: 1
Hi I am using this piece of code to post an image to facebook
UIImage *image_LocalSharePhoto = [[UIImage alloc]initWithData:sharedSingleton.dataResultImage];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
@"Put Captions On Pics", @"name",
@"Put Captions On Pics", @"caption",
image_LocalSharePhoto,@"picture",
@"I created this fun photo using a FREE app http://bit.ly/CapsPics. #PutCapsOnPics via @PutCapsOnPics", @"description",
nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"532872463436844", @"api_key",
@"Share on Facebook", @"user_message_prompt",
attachmentStr, @"attachment",
nil];
[facebook dialog: @"feed" andParams:params andDelegate:self];
It opens up facebook page but do not show anything to share or post. Can some one help. Thanks!
Upvotes: 0
Views: 184
Reputation: 49710
if you are using old facebook Method you can wall post like bellow Methid:-
NSArray* permissions = [NSArray arrayWithObjects:@"publish_stream", @"user_photos", nil];
[facebook authorize:permissions];
now to Post image At your Button Click or your logic like:-
-(IBAction)ActionPostWallPhoto
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
ImageView.image, @"picture",
nil];
[[objAppdele facebook] requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
}
and if you are using new facebook API then you can use bellow Method:-
NSMutableDictionary *postTest = [[NSMutableDictionary alloc]init];
[postTest setObject:[NSString stringWithFormat@"Your message"] forKey:@"message"];
[postTest setObject:@"" forKey:@"picture"];
[postTest setObject:@"" forKey:@"name"];
[postTest setObject:@"APPID" forKey:@"app_id"];
NSString *userFBID =[NSString stringWithFormat:@"%@",[allInfoDict objectForKey:@"Friends facebook ID "]];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/feed?access_token=%@",userFBID,[appDelegate.mysession accessToken]]
parameters:postTest
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
NSDictionary * result,
NSError *error) {
if (error) {
NSLog(@"Error: %@", [error localizedDescription]);
} else {
// Success
}
}];
[postTest release];
Upvotes: 1
Reputation: 1318
if you are using facebook's api , I am able to share the images on user's timeline using following code ... Please review the code if it can help .. include
// aryFetchedImages = Array of images which needs to be posted on Facebook
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
for (int i = 0; i < aryFetchedImages.count ; i++)
{
[params setObject:UIImageJPEGRepresentation([aryFetchedImages objectAtIndex:i], 50.0f) forKey:@"picture"];
[FBRequestConnection startWithGraphPath:@"me/photos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
#ifdef DEBUG
NSLog(@"Unable to share the photo please try later - Fail %@",error);
#endif
}
else
{
//showing an alert for success
#ifdef DEBUG
NSLog(@"Photo %@ uploaded on Facebook Successfully",UIImageJPEGRepresentation([aryFetchedImages objectAtIndex:i], 50.0f));
#endif
}
}];
}
Upvotes: 2