Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-09-2011, 08:03 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 3
anodeyes is on a distinguished road
Default facebook ios sdk - trouble posting photo using UIImage

Hi all-

I'd be grateful for any suggestions as to how to deal with a problem I'm having posting an image to Facebook.

The following code works just as I would expect:

Code:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                     @"http://myserver/img.png", @"picture",
                     @"My Testing", @"name",
                     @"Enter some text...",  @"message",
                     nil];

[appDelegate.facebook dialog:@"feed" andParams:params andDelegate:self];
However, I really want to use an image that I capture from my camera. I've set up the code to do that earlier in my application and I've put the image on the screen. So, I tried to do this:

Code:
CGRect contextRect  = CGRectMake(0, 0, 320, 436);
UIGraphicsBeginImageContextWithOptions(contextRect.size, YES, 1);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I've tested this code and newImage is a valid UIImage that I can place and manipulate just as I'd expect. However, when I try to integrate it into the Facebook dialog as follows:

Code:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                     newImage, @"picture",
                     @"My Testing", @"name",
                     @"Enter some text...",  @"message",
                     nil];

[appDelegate.facebook dialog:@"feed" andParams:params andDelegate:self];
I get these two ridiculous messages in the console:
-[UIImage length]: unrecognized selector sent to instance 0x1c9420
CoreAnimation: ignoring exception: -[UIImage length]: unrecognized selector sent to instance 0x1c9420

So, as a test, I thought I'd try importing an image into my project and accessing it directly. This is the exact image as I referenced online in the first example, so I know it should work. But even when I try this:

Code:
UIImage *newImage = [UIImage imageNamed:@"BaB.png"];
I get the same error messages as above.

I see in the Facebook documentation that the "picture" key is supposed to use the URL to an image. But I've seen some examples online that indicate that folks are using an UIImage instead of just an URL.

Clearly, I'm doing something wrong, but I have no idea what it might be.

I'd be very grateful for any pointers as to how to proceed.

Thanks so much.

Peace.

Joel
anodeyes is offline   Reply With Quote
Old 07-10-2011, 07:15 PM   #2 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 324
mariano_donati is on a distinguished road
Default

That error comes because the "picture" param is actually expecting an NSString object containing an url to the image. You can't upload a picture along a comment. You need to store it on some server before, get its url and pass it as param.
You can only upload a photo if you add it to an album i.e. using photos.upload request.
I haven't tested, but maybe you could upload the photo to an album and see if you can get its url. Since you will not be using the feed dialog for uploading the photo, you'll need to ask for publish_stream permission.
mariano_donati is offline   Reply With Quote
Old 07-11-2011, 07:23 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 3
anodeyes is on a distinguished road
Default

Thanks so much for taking time to explain that to me. That makes sense.

But I'm left with a lingering question - does this mean that there's really no direct way to post a photo taken with the iPhone camera to Facebook using the Facebook dialog method, and instead I have to use the Facebook Graph method?
anodeyes is offline   Reply With Quote
Old 07-11-2011, 07:28 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 324
mariano_donati is on a distinguished road
Default

Well, I really didn't play around with it for a very long time, so I really can't assure that it is not possible. Have you tried uploading it through photos.upload and then trying to get its url and post that along the comment?
mariano_donati is offline   Reply With Quote
Old 07-13-2011, 03:31 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 3
anodeyes is on a distinguished road
Default

Thanks. I ended up doing it directly. Uploading and then getting the resultant URL was just too cumbersome. I appreciate your assistance.
anodeyes is offline   Reply With Quote
Old 07-13-2011, 04:47 PM   #6 (permalink)
Registered Member
 
Objective Zero's Avatar
 
Join Date: Oct 2010
Posts: 1,210
Objective Zero is on a distinguished road
Default

What was your final code, I would like to know for my app
__________________
Questions?

Check out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
Objective Zero is offline   Reply With Quote
Old 07-14-2011, 03:56 PM   #7 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 633
ilmman is on a distinguished road
Default

yes i would also like to know how to do this method directly I have the same problem of having it only work on URL images only too :P
ilmman is offline   Reply With Quote
Old 05-07-2012, 03:43 AM   #8 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 36
AppleSteve is on a distinguished road
Default

Quote:
Originally Posted by ilmman View Post
yes i would also like to know how to do this method directly I have the same problem of having it only work on URL images only too :P
Yeah... Please share your code....
AppleSteve is offline   Reply With Quote
Reply

Bookmarks

Tags
facebook, post, uiimage

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 361
10 members and 351 guests
apatsufas, chemistry, lendo, leostc, Leslie80, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:35 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0