How To upload Video on Facebook using FBConncet? - iphone

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

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.

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

Related

Share image from bundle and link on Facebook in iphone

I want to share image,link etc to Facebook from my iphone app.My app Link,cation,name and description posted successfully. But i can't share image. Please follow my code..
UIImage *image = [UIImage imageNamed:#"sample.png"];
NSData *imgData = UIImageJPEGRepresentation(image, 1.0);
self.dictionary =[[NSMutableDictionary alloc] initWithObjectsAndKeys: #"https://www.google.com/ios", #"link",
imgData, #"data",
#"AppName", #"name",
#"Testing", #"caption",
#"say something about this", #"description",
nil];
my share facebook code is..
[facebook requestWithGraphPath:#"/me/feed" andParams:dictionary andHttpMethod:#"POST" andDelegate:self];
My problem is how to take image from bundle and how to share selected image to Facebook?Please help me..
use like below:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"image1" ofType:#"png"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"My hat image", #"message", data, #"source", nil];
[facebook requestWithGraphPath:#"/me/photos" andParams:params andHttpMethod:#"POST" andDelegate:self];

how can I post large video on facebook sdk in iOS?

I am using facebook sdk for uploading videos, but I am not able to upload more than 60MB video on facebook. I tried a lot using NSInputStream also for sending data and all :-
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"mov"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, #"video.mov",
#"video/quicktime", #"contentType",
#"Video Test Title", #"title",
#"Video Test Description", #"description",
nil];
FBRequest *request = [FBRequest requestWithGraphPath:#"me/videos" parameters:params HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"result: %#, error: %#", result, error);
}];
Use dataWithContentsOfFile:options instead. Doesn't try to load all the data into memory, which may make your app getting closed by iOS:
NSData *videoData = [NSData dataWithContentsOfFile:video.localURL options:NSDataReadingMappedAlways error:&error];

Facebook integration showing alert address is invalid

I am new in iPhone application development. Now i am developing application for iPhone In this application I need to upload video to Facebook. i am used below code. Now enter Facebook the user name and password. showing error message alert. like safari cannot open the page because the address is invalid.
- (void)viewDidLoad
{
facebook = [[Facebook alloc] initWithAppId:#"Facebook_App_Id"];
//#"com.facebook.samples.VideoUploadTest"];
facebook.sessionDelegate = self;
}
- (IBAction)buttonClicked:(id)sender {
NSArray* permissions = [[NSArray alloc] initWithObjects:
#"publish_stream", nil];
[facebook authorize:permissions delegate:self];
[permissions release];
}
- (void)fbDidLogin {
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"mov"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, #"video.mov",
#"video/quicktime", #"contentType",
#"Video Test Title", #"title",
#"Video Test Description", #"description",
nil];
[facebook requestWithGraphPath:#"me/videos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
referred from this url [http://developers.facebook.com/blog/post/532/]
Refer this for SSO settings.
http://developers.facebook.com/docs/mobile/ios/build/

How to upload multiple images to facebook from iphone sdk

i want to upload Multiple images to Facebook from iphone. And i have search so many things and made a code as below: but it's not working. Any help will be appreciated.
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *jsonRequest1 = #"{ \"method\": \"POST\", \"relative_url\": \"me/photos\" , \"body\": \"Hello 1\", \"attached_files\": \"file1\" }";
NSString *jsonRequest2 = #"{ \"method\": \"POST\", \"relative_url\": \"me/photos\" , \"body\": \"Hello 2\", \"attached_files\": \"file2\" }";
NSString *jsonRequestsArray = [NSString stringWithFormat:#"[ %#, %# ]", jsonRequest1, jsonRequest2];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:jsonRequestsArray,#"batch",nil];
NSString *url1=#"http://uhallnyu.files.wordpress.com/2011/11/green-apple.jpg";
NSString *url2=#"http://scm-l3.technorati.com/12/04/24/67277/apple.gif?t=20120424140104";
NSData *data1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:url1]];
UIImage *img1 = [[UIImage alloc] initWithData:data1];
NSData *data2 = [NSData dataWithContentsOfURL:[NSURL URLWithString:url2]];
UIImage *img2 = [[UIImage alloc] initWithData:data2];
[params setObject:img1 forKey:#"file1"];
[params setObject:img2 forKey:#"file2"];
[[delegate facebook] requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
You can upload photos to facebook using :-
You can have a switch case to read the type of image from your image file and get imagedata using functions UIImagePNGRepresentation,UIImageJPEGRepresentation,etc.
NSData *yourImageData= UIImagePNGRepresentation(yourImage);
Initialize the dictionary :-
NSMutableDictionary *mutableDictWithParam= [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Your text", #"message", yourImageWithData, #"theSource", nil];
finally send post :-
[facebook requestWithGraphPath:#"/me/photos" andParams:mutableDictWithParam andHttpMethod:#"POST" andDelegate:self];
You can have it in loop to send more than one image.

Framework for uploading images with titles to Facebook

I see in the internet codes that do upload images but the use "Facebook" that isn't recognized, so which framework do I need to use in iOS?
Do you have a code example?
I found this code:
- (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", #"my photo's caption text here.", #"message", nil];
[facebook requestWithMethodName: #"photos.upload" andParams:params andHttpMethod:#"POST" andDelegate:self];
[img release];
}
You'll need to add the Facebook iOS SDK to your project.
All the details you need should be found here