I have been trying to post a photo on facebook using facebook graph API. After authenticating user I am doing as following
NSMutableDictionary *variables = [[NSMutableDictionary alloc]init];
[variables setObject:#"some text" forKey:#"message"];
[variables setObject:#"some link" forKey:#"link"];
[variables setObject:[UIImage imageNamed:#"icon#2x.png"] forKey:#"picture"];
NSString *str = #"me/feed";
NSLog(#"str: %#", str);
FbGraphResponse *resp = [self.fbGraph doGraphPost:str withPostVars:variables];
NSLog(#"resp: %#", resp.htmlResponse);
But my app crashes by throwing an exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: -[UIImage dataUsingEncoding:]: unrecognized selector sent to instance 0x11545140'
So some one can help me how do i post an image on Facebook wall along with some message using graph API.
Use the given below code
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:3];
//create a UIImage (you could use the picture album or camera too)
//UIImage *picture =selectimage.image;
UIImage *picture =[self scaleAndRotateImage:selectimage.image];
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
[variables setObject:graph_file forKey:#"file"];
[variables setObject:myPost.text forKey:#"message"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"me/photos" withPostVars:variables];
Related
I am posting a post on facebook. I am able to post a URL but I also want to post some description with that URL. I am using it -
NSString *shareUrlString = [NSString stringWithFormat:#"http://www.facebook.com/sharer.php?u=%#&t=%#", urlString , description];
NSURL *url = [ [ NSURL alloc ] initWithString:urlString ];
[[UIApplication sharedApplication] openURL:url];
but I am not able to post description. So can you gave any idea to do this. I don't want to use any sdk or any api for to do it.
Use iPhone-Facebook-Graph-API as easy to use.
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:#"MESSAGE HERE" forKey:#"message"];
[variables setObject:#"URL HERE" forKey:#"link"];
[variables setObject:#"URL NAME HERE" forKey:#"name"];
[variables setObject:#"URL DESC HERE." forKey:#"description"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"me/feed" withPostVars:variables];
I am using this code to post any text on the facebook page with the page id menetioned in the code. it gives success message but when i goto the page there is nothing.
Pls help...
Thanks in advance
-(void)facebookPost;
{
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
FbGraphFile *graph_file = [[FbGraphFile alloc]init]; //initWithImage:[UIImage imageNamed:#"gg"]];
//finally, set the FbGraphFileobject onto our variables dictionary....
[variables setObject:graph_file forKey:#"file"];
[variables setObject:#"hihihi" forKey:#"message"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:[NSString stringWithFormat:#"%#/167884363345570/feed",FACEBOOK_APP_KEY] withPostVars:variables];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:[NSString stringWithFormat:#"%#/167884363345570/feed",FACEBOOK_APP_KEY] withPostVars:variables];
}
Error was in this line...
wrong:
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:[NSString stringWithFormat:#"%#/167884363345570/feed",FACEBOOK_APP_KEY] withPostVars:variables];
Right way is this:
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:[NSString stringWithFormat:#"167884363345570/feed"] withPostVars:variables];
And i have solved the problem.
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...");
}
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];
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];