简体   繁体   中英

How to use FBConnect dialog method to post a UIImage to my wall?

( Note: I've looked all over for this, and there are tons of examples for how to post a URL-to-image via dialog, and a few for how to post image-data direct to photo album, but neither of those are what I'm trying to do.)

I can post an image that's stored on the web easily enough with code similar to this:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
        @"This is what I say about kittens!", @"message",
        @"Kittens!", @"name",
        @"I'm feeling fuzzy", @"caption",
        @"You, too, can feel fuzzy, with FuzzyKitten™", @"description",
        @"http://example.com/fuzzykitten.html", @"link",
        @"http://placekitten.com/200/150", @"picture",
        nil];

[facebook dialog: @"feed"
            andParams: params
            andDelegate: self];

And everything works fine. The problem is, I'd like to replace:

        @"http://placekitten.com/200/150", @"picture",

with something along the lines of:

        [UIImage imageNamed: @"myImage.png"], @"picture",

which, of course, isn't right. So my question is: If I have an image in UIImage form, how do I load that into the parameters dictionary to pass to the dialog method?

Thanks!

EDIT: This is a client iPhone app for which there is no server so, while uploading the image to FB as part-1 of a 2-part process is fine, I'm now not seeing how to find the uploaded image's URL. Thanks again!

You can't directly upload an image to the wall, when publishing to the wall you can just link an image to it.
So, you need to upload the UIImage somewhere first. You have 2 options:
1. Upload to your/some server and publish a wall post linking to it.
2. Upload to a facebook album. Check the graph API about doing that, it is pretty straightforward.

edit: you can no longer source images hosted in facebook CDN (and probably other CDNs), so if you need to link an image from a dialog you should upload it on a server and get a permalink from there

You could use ASIFormDataRequest and run a script to upload your file to your server using something like this:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

// Upload a file on disk
[request setFile:@"/Users/ben/Desktop/ben.jpg" withFileName:@"myphoto.jpg" andContentType:@"image/jpeg"
forKey:@"photo"];

Then have the ASIFormDataRequest's response return the url of the uploaded image to your application. You can use the event of the ASIFormDataRequest response to trigger the Facebook image post.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM