Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Connect on iOS - Picture doesn't display with wall post

I've set up Facebook connect with my app using the demo project provided by Facebook. Everything works great, except for the last little step...

  • First of all, I login and get permissions.

  • Next, I upload a picture. This works great, I can see the picture in my Facebook album like I should be able to.

  • When this picture is uploaded, I get it's URL (returned by the FBRequest delegate). Copy pasting this URL into a web browser takes me directly to the image, so I know that this URL is correct.

Here's where the problem is:

  • I now want to present this picture alongside a wall post. The wall post is fine, but the picture just doesn't seem to attach and the status is left as a plain text message.

Here's the code I'm using for the last part:

- (void)request:(FBRequest *)request didLoad:(id)result {

    NSString* picUrl = [result objectForKey:@"src_big"];  //this definitely returns the right URL

    if (picUrl)
    {
        NSString *message = @"Test status";
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       message, @"message", picUrl, @"picture", @"Look at my photo", @"name", nil];

        [facebook requestWithMethodName:@"facebook.Stream.publish" andParams:params
                          andHttpMethod:@"POST" andDelegate:self];
    }
}

Any ideas what I'm missing or doing wrong?

like image 212
Jordan Smith Avatar asked Mar 27 '11 10:03

Jordan Smith


1 Answers

Fixed with the following code (after a lot of failed attempts). Facebook doesn't like the way I was trying it, you've got to do it all in just one step:

NSData *imageData = UIImagePNGRepresentation(image);

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Test message", @"message", imageData, @"source", nil];

[facebook requestWithGraphPath:@"/me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];
like image 131
Jordan Smith Avatar answered Nov 07 '22 11:11

Jordan Smith