0

How to post large image on facebook wall through iphone programmatically.I am using FBConnect API how can i acheive this.

Thanks

  • even if you send original image, facebook will automatically resize it to 720x720 (or something). So facebook recommends to resize images to max 720px before sending, to save user traffic/time while sending. – jamapag Sep 27 '11 at 10:39

3 Answers3

0

Facebook docs said:

It is strongly recommended that you scale the image in your application before adding it to the request. The largest dimension should be at most 720 pixels (the largest display size Facebook supports).

jamapag
  • 9,290
  • 4
  • 34
  • 28
0
-(void)postMessageWithPictureOnFB{


    NSString *urlString = [[NSString alloc] initWithFormat:@"https://graph.facebook.com/me/photos"];
    NSURL *url = [[NSURL alloc] initWithString:urlString];

    NSData *picture_data =  UIImagePNGRepresentation([UIImage imageNamed:@"apple.png"]);
    NSMutableData *body = [[NSMutableData alloc] initWithCapacity:1];
    NSString *boundary = [[NSString alloc] initWithString:@"----1010101010"];
    NSString *contentType = [[NSString alloc] initWithFormat:@"multipart/form-data; boundary=%@",boundary];

    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition: form-data; name=\"message\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[textView.text dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"media\";\r\nfilename=\"media.png\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:picture_data];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition: form-data; name=\"access_token\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[facebook.accessToken dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

    serverRequest = [ASIHTTPRequest requestWithURL:url];
    [serverRequest addRequestHeader:@"Content-Type" value:contentType];
    [serverRequest appendPostData:body];
    [serverRequest addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d", body.length]];
    //[serverRequest setDelegate:self];
    //[serverRequest setDidFinishSelector:@selector(postMessageWithPictureOnFBRequestDone:)];
    //[serverRequest setDidFailSelector:@selector(postMessageWithPictureOnFBRequestWentWrong:)];
    [serverRequest startAsynchronous];

    [urlString release];
    [url release];
    [body release];
    [boundary release];
    [contentType release];
}
nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Aman Gupta
  • 433
  • 3
  • 9
0

Try this with Graph API

 - (IBAction)uploadPhoto:(id)sender {

NSString *path = @"http://www.facebook.com/images/devsite
                     /iphone_connect_btn.jpg";
 NSURL *url = [NSURL URLWithString:path];
 NSData *data = [NSData dataWithContentsOfURL:url];
 UIImage *img  = [[UIImage alloc] initWithData:data];

 NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                             img, @"picture",
                             nil];

 [_facebook requestWithGraphPath:@"me/photos"
                    andParams:params
                    andHttpMethod:@"POST"
                    andDelegate:self];

[img release];

}

Karthikeyan
  • 1,790
  • 12
  • 19