Reputation: 55
Please find below my code to share on friends wall
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
// if we don't have permission to announce, let's first address that
if ([appDelegate.session.permissions indexOfObject:@"publish_actions"] == NSNotFound)
{
NSArray *permissions =[NSArray arrayWithObjects:@"publish_actions",@"publish_stream",@"manage_friendlists", nil];
[FBSession setActiveSession:appDelegate.session];
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error)
{
if (!error)
{
// have the permission
[self poster];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}];
}
else
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_friendId, @"to",
@"text change", @"caption",
@"Some Text", @"description",
@"http://example.com/pic.png", @"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
//stuff
}];
}
This works fine, but when am trying to place local image instead of the picture url, the app crashes
[UIImage imageNamed:@"troll.png"], @"picture"
Upvotes: 1
Views: 1700
Reputation: 20753
If you read the documentation-
picture: The URL of a picture attached to this post. The picture must be at least 200px by 200px.
So, you cannot pass the image data to the feed- only a link to that picture will work.
To solve this, you just have 2 options-
Save the image to a server, and generate the link and pass this link to the picture
parameter.
Upload the image in facebook using - this wont work check "Edit-2"\POST /photos
, then use its link in the picture
parameter.
Edit 1: To get the picture link-
[FBRequestConnection startWithGraphPath:@"/{photo-id}?fields=picture"
parameters:nil
HTTPMethod:@"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
}];
(This can be ignored since facebook cdn images cant be used in the picture
parameter. Check "Edit-2")
Edit 2:
According to the facebook guys-
object_attachment
is not supported for feed dialogs.picture
is the correct method to modify the image for your post. However, you can not specify an image from Facebook's CDN for this parameter.
So I guess you are just left with one option- to upload phorto on other server than facebook and use that url in the picture
parameter.
Upvotes: 1