Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure what part isn't working for you, since you are posting and getting an ID back, but here is what I did in a quick and dirty way, in case someone reaches here via Google.</p> <p>This is an HTTP POST function, and the binary data of the file goes up as multipart mime.</p> <p>I'm a big fan of the ASIHTTPRequest library available <a href="http://allseeing-i.com/ASIHTTPRequest/" rel="nofollow noreferrer">here</a>.</p> <p>**UPDATE: 10/22/2012 ** - AFNetworking has replaced ASIHTTPRequest in my code in the past few months. Available on GitHub <a href="https://github.com/AFNetworking/AFNetworking" rel="nofollow noreferrer">here</a></p> <p>Facebooks docs are confusing, partly because they are incomplete and partly because they can be wrong. You'll probably tear some hair out figuring out exactly what post value to set for a caption or something, but this recipe puts a photo into an album, and that goes into the feed.</p> <p>You still need to set up the Facebook OAuth stuff in the basic way - I happened to do that in the app delegate, so I grab the Facebook object from there to get my access token. I made sure to ask for the "publish_stream" permission when I authenticated, like this:</p> <pre><code>[facebook authorize:[NSArray arrayWithObjects:@"publish_stream", nil] delegate:self]; </code></pre> <p>This will create or add to an album called "YOUR_APP_NAME Photos", and will appear in the user's feed. You can put it in any album, including the "Wall" album, by getting the ID of that album and changing the URL to <a href="http://graph.facebook.com/THE_ID_OF_THE_ALBUM/photos" rel="nofollow noreferrer">http://graph.facebook.com/THE_ID_OF_THE_ALBUM/photos</a>.</p> <p>Here's the basic method:</p> <pre><code>-(void) postImageToFB:(UIImage *) image { NSData* imageData = UIImageJPEGRepresentation(image, 90); Facebook* fb = [(uploadPicAppDelegate *)[[UIApplication sharedApplication] delegate] facebook ]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"https://graph.facebook.com/me/photos"]]; [request addPostValue:[fb accessToken] forKey:@"access_token"]; [request addPostValue:@"image message" forKey:@"message"]; [request addData:imageData forKey:@"source"]; [request setDelegate:self]; [request startAsynchronous]; } </code></pre> <p>Using the Facebook provided iOS library looks like this:</p> <pre><code>-(void) postImageToFB:(UIImage *) image { NSData* imageData = UIImageJPEGRepresentation(image, 90); Facebook* fb = [(uploadPicAppDelegate *)[[UIApplication sharedApplication] delegate] facebook ]; NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[fb accessToken],@"access_token", @"message text", @"message", imageData, @"source", nil]; [fb requestWithGraphPath:@"me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload