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];
Related
I want to share an image with Url, title, caption and message. I am using Facebook connect to do that. After successful facebook login I am using the following code to share the image.
NSLog(#"card image = %#",[MyClass getcardImage]);
// This log gives me an image object like <UIImage: 0x1f32d450>
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
nil];
[params setObject:#"An Image" forKey:#"name"];
[params setObject:[MyClass getCardURL] forKey:#"link"];
[params setObject:#"My Image" forKey:#"caption"];
[params setObject:#"Sharing myImage" forKey:#"message"];
[params setObject:UIImagePNGRepresentation([MyClass getcardImage]) forKey:#"picture"];
[params setObject:#"Hey! I am sharing my picture" forKey:#"description"];
[FBRequestConnection
startWithGraphPath:#"me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSString *alertText;
if (error) {
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
} else {
alertText = [NSString stringWithFormat:
#"Posted action, id: %#",
result[#"id"]];
}
I get error message like error: domain = com.facebook.sdk, code=5
But when I just remove the following line from params dictionary,
[params setObject:UIImagePNGRepresentation([MyClass getcardImage]) forKey:#"picture"];
The code works well.
Whats wrong in that line.
I want to add image as well.
The "me/feed" endpoint only accepts urls for the "picture" parameter, and not the image data.
See https://developers.facebook.com/docs/reference/api/user/#posts
So you should only include a url to an image, but not the image itself.
Actually, I use this code:
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"message" forKey:#"message"];
[params setObject:#"status" forKey:#"type"];
[params setObject:#"name" forKey:#"name"];
[params setObject:#"caption" forKey:#"caption"];
[params setObject:#"description" forKey:#"description"];
[params setObject:#"http://www.domain.de/picture.png" forKey:#"picture"];
This works, but the name now link to the picture-URL.
How can I link to the domain without using the key "link", because I like to post a status message, not a link (like in the app runtastic)
Thanks,
Christian
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...");
}
I have made one application, In my application I have integrate Facebook for sharing information.
for Facebook integration I have use Graph API in application.
now In my application, I want to upload photo on user's wall.
I have use this code for upload photo on user's wall.
// for upload photo
- (void)uploadPhoto:(id)sender {
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Image1" ofType:#"jpg"];
NSString *message = [NSString stringWithFormat:#"I think this is a Great Image!"];
NSURL *url = [NSURL URLWithString:#"https://graph.facebook.com/me/photos"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addFile:filePath forKey:#"file"];
[request setPostValue:message forKey:#"message"];
[request setPostValue:_accessToken forKey:#"access_token"];
[request setDidFinishSelector:#selector(sendToPhotosFinished:)];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)sendToPhotosFinished:(ASIHTTPRequest *)request {
// Use when fetching text data
NSString *responseString = [request responseString];
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *photoId = [responseJSON objectForKey:#"id"];
NSLog(#"Photo id is: %#", photoId);
NSString *urlString = [NSString stringWithFormat:
#"https://graph.facebook.com/%#?access_token=%#", photoId,
[_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url];
[newRequest setDidFinishSelector:#selector(getFacebookPhotoFinished:)];
[newRequest setDelegate:self];
[newRequest startAsynchronous];
}
But, here I get
responseString is {"error":{"message":"Error validating application.","type":"OAuthException"}} and
Photo id is: (null)
and Image is not upload on user's wall.
so, please tell me how to solve it.
First have you authorized your application to upload pictures by doing this (using the FBConnect SDK), you can checkout all permissions here
NSArray* permissions = [NSArray arrayWithObjects:#"publish_stream", #"user_photos", nil];
[facebook authorize:permissions];
The next problem is that facebook does not allow posts sent in this way to link to pictures hosted on their domains (I know it's REALLY annoying, maybe it would be worth checking if things have changed since april). I spent quite a bit of time working this one out. The way I cracked it was to create a redirect URL using bitly (you can access their services programatically using their API, there's an obj-c wrapper for it here, although I changed it to be asynchronous) and send that URL in the post.
may help u
//facebook post a image on wall
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
userImgView.image, #"picture",
nil];
[facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
another way is bellow for post image on Facebook ...
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
//create a UIImage (you could use the picture album or camera too)
UIImage *picture = [UIImage imageNamed:"yourImageName"];
//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:#"write your Message Here" 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];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"me/photos" withPostVars:variables];
hope , this help you...
:)
The facebook API uses OAuth to authenticate requests. You will need to use a library that can request the appropriate temporary/client tokens, and generate the appropriate HTTP headers for requests. This is quite a complicated procedure which involves hashing and normalizing of request arguments.
You cannot do this crafting your own manual HTTP requests .
You can use facebook's native function
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: UIImageJPEGRepresentation(postImage, 1.0), #"source", self.postTextView.text, #"message", nil];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/me/photos" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (error == nil) {
NSLog("Success");
}
else {
NSLog("Failed");
}
}];
Using this code you can post image with message.
Best regards