Issues with posting image on fb wall via graph api? - iphone

AI am using following code to post image on user's wall on facebook
NSData *imageData =UIImagePNGRepresentation(newPageView.image);
UIImage *picture = [UIImage imageWithData:imageData];
NSLog(#"picture is %#",picture);
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
[variables setObject:graph_file forKey:#"file"];
[variables setObject:#"this is a test message: postPictureButtonPressed" forKey:#"message"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"/me/photos" withPostVars:variables];
Above code post image in photos album.how can i change it to post image on wall?

try this code
NSURL *url = [NSURL URLWithString:#"YOur Image url"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
[variables setObject:img forKey:#"picture"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"/me/photos" withPostVars:variables];

Related

How To upload Video on Facebook using FBConncet?

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

Share Image and text on facebook wall in iphone is not working?

hello Guys, I want to share image directly in iphone and share text also .
I have implemented the following code on button click but it is doing nothing...
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:[NSString stringWithFormat:#"Hi... Testing APp"] forKey:#"message"];
[variables setObject:#"http://icon.png" forKey:#"picture"]; //http://tinyurl.com/45xy4kw
[variables setObject:#"Create post" forKey:#"name"];
[variables setObject:#"Write description." forKey:#"description"];
[facebook requestWithGraphPath:#"/me/feed" andParams:variables andHttpMethod:#"POST" andDelegate:self];
I m using facebook direct api for this
Facebook API
Use this code its working fine
-(IBAction)postMeFeedButtonPressed:(id)sender {
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:8];
//create a UIImage (you could use the picture album or camera too)
UIImage *picture = [UIImage imageNamed:#"Icon#2x.png"];
//create a FbGraphFile object insance and set the picture we wish to publish on it
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
//finally, set the FbGraphFileobject onto our variables dictionary....
[variables setObject:graph_file forKey:#"file"];
NSArray *idarry=[[NSArray alloc]initWithArray:Delegate.IdListArray];
NSLog(#"Delegate array %#",Delegate.IdListArray);
//NSString *str=[NSString stringWithFormat:#"100001912715296,100001912715296"];
NSString *str=[idarry componentsJoinedByString:#","];
NSLog(#"The string contents are %#",str);
NSString *idstr=[NSString stringWithFormat:#"100002875785051,100001912715296"];
[variables setObject:idstr forKey:#"tags"];
[variables setObject:#"110506962309835" forKey:#"place"];
[variables setObject:#"Hello All my dear friends,I am using MySafety APP" forKey:#"message"];
[variables setObject:#"http://techilasolutions.com/product.html" forKey:#"link"];
[variables setObject:#"My Safety" forKey:#"name"];
[variables setObject:#"http://techilasolutions.com/images/car_tag.png" forKey:#"picture"];
[variables setObject:#"This is a must have app for all women whether you are a working lady, a house wife or a school going girl.This app lets you save 6 emergency contacts whom you want to alert in case of emergency.Whenever you feel you are in danger, just press the SOS button and it will send sms to your contacts with your current location and a alarm will go on with flashing lights" forKey:#"description"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"me/feed" withPostVars:variables];
NSLog(#"postMeFeedButtonPressed: %#", fb_graph_response.htmlResponse);
//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
[parser release];
//let's save the 'id' Facebook gives us so we can delete it if the user presses the 'delete /me/feed button'
self.feedPostId = (NSString *)[facebook_response objectForKey:#"id"];
NSLog(#"feedPostId, %#", feedPostId);
NSLog(#"Now log into Facebook and look at your profile...");
}
You can post image using this code try this code once.
-(IBAction)postPictureButtonPressed:(id)sender
{
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
UIImage *picture = [UIImage imageNamed:#"75x75.png"];
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
[variables setObject:graph_file forKey:#"file"];
[variables setObject:#"this is a test message: postPictureButtonPressed" forKey:#"message"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"117795728310/photos" withPostVars:variables];
NSLog(#"postPictureButtonPressed: %#", fb_graph_response.htmlResponse);
NSLog(#"Now log into Facebook and look at your profile & photo albums...");
}

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

Facebook Graph API Crashing My App

he problem is when i come to use the post function a section time. The app will crash out kicking out the error below...
Program received signal: “EXC_BAD_ACCESS”.
I'm using the code below .But image is post to Facebook.
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
//create a UIImage (you could use the picture album or camera too)
NSData *imageData = UIImageJPEGRepresentation(imgView.image, 8.0);
UIImage *picture = [UIImage imageWithData:imageData];
//create a FbGraphFile object insance and set the picture we wish to publish on it
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
//finally, set the FbGraphFileobject onto our variables dictionary....
[variables setObject:graph_file forKey:#"file"];
[variables setObject:#"i'm testing my iPhone App" forKey:#"message"];
//the fbGraph object is smart enough to recognize the binary image data inside the FbGraphFile
//object and treat that is such.....
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"117795728310/photos" withPostVars:variables];
NSLog(#"postPictureButtonPressed: %#", fb_graph_response.htmlResponse);
NSLog(#"Now log into Facebook and look at your profile & photo albums...");
Plz help me for solving this problem.
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:1];
NSData *dataImage=UIImageJPEGRepresentation(FilterImage, 1.0);
UIImage *picture =[[UIImage alloc]initWithData:dataImage];
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
[variables setObject:graph_file forKey:#"file"];
//[variables setObject:[NSString stringWithFormat:#"Testing App"] forKey:#"message"];
[fbGraph doGraphPost:#"me/photos" withPostVars:variables];
NSLog(#"Now log into Facebook and look at your profile & photo albums...");
[picture release];
picture=nil;
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
replace above
NSMutableDictionary *variables = [[NSMutableDictionary alloc] initWithCapacity:2];