0

In my application i am trying to upload Video on facebook wall using FbConnect my Code looks oky But i Don't know why my Video is not uploaded Beacuse if i use the Same Code method for Uploading image it successfully upload the image on facebook.here is my code which i use for image uploading

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"png"];
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfFile:filePath];
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];

And for Video i am trying this Code so For

 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mp4"];
 NSURL *url = [NSURL URLWithString:filePath];
 NSData *videoData = [NSData dataWithContentsOfURL:url];
 NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               videoData, @"video.mp4",
                               @"video/quicktime", @"contentType",
                               @"Video Test Title", @"title",
                               @"Video Test Description", @"description",
                               nil];
[_facebook requestWithGraphPath:@"me/videos"
                     andParams:params
                 andHttpMethod:@"POST"
                   andDelegate:self];

The Above code give me no error but it retun some text msg in label (the operation Could not be completed).Which is not in case of image uploading.So can some guide me how to fix it.Thanks

NSCool
  • 229
  • 1
  • 12

2 Answers2

5

Try these lines:

 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mp4"];
      NSData *videoData = [NSData dataWithContentsOfFile:filePath];
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   videoData, @"video.mp4",
                                   @"video/quicktime", @"contentType",
                                   @"Video Test Title", @"title",
                                   @"Video Test Description", @"description",
                                   nil];
    [_facebook requestWithGraphPath:@"me/videos"
                         andParams:params
                     andHttpMethod:@"POST"
                       andDelegate:self];

Hope this help you.its working fine for me.Now add these lines.

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
Vishal
  • 8,246
  • 6
  • 37
  • 52
  • your code give me warning warning: incompatible Objective-C types 'struct NSString *', expected 'struct NSURL *' when passing argument 1 of 'dataWithContentsOfURL:' from distinct Objective-C type – NSCool Dec 10 '12 at 11:14
  • 1
    NSData *videoData = [NSData dataWithContentsOffile:filePath]; Add this line now its working for you.try it. – Vishal Dec 10 '12 at 11:21
3
 http://stackoverflow.com/questions/10509984/how-to-upload-mp4-video-on-facebook-using-graph-api-in-objective-c

http://%5B1%5D:%20https://github.com/reallylongaddress/iPhone-Facebook-Graph-API

http://stackoverflow.com/questions/12861615/upload-video-to-facebook-using-facebook-new-sdk-on-ios-6-0
Bajaj
  • 859
  • 7
  • 17
  • Sahil tell me one thing can i fix the Existing code beacuse same code works when i used it for image. – NSCool Dec 10 '12 at 11:18