How to post to a friends Wall using Facebook Graph API [duplicate] - ios

This question already has answers here:
How to post on a friend's Timeline after the February 2013 migration takes effect?
(4 answers)
Since Feb. 6th, can I post to friends' timeline by Graph API call directly?
(1 answer)
Closed 9 years ago.
I am working on an application on facebook integration using fbgraph api.I have downloaded sample application from this link oAuth2Test and then changed client_id.While post on me it is working fine but I don't know how to post on a friends wall or if this is possible.
Or at least to send his friends a message.
Can anyone give me a clue?
Thank you!
posting me working fine
-(IBAction)postMeFeedButtonPressed:(id)sender {
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:#"this is a test message: postMeFeedButtonPressed" forKey:#"message"];
[variables setObject:#"http://bit.ly/bFTnqd" forKey:#"link"];
[variables setObject:#"This is the bolded copy next to the image" forKey:#"name"];
[variables setObject:#"This is the plain text copy next to the image. All work and no play makes Jack a dull boy." 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...");
}

Related

why publishing to facebook wall using graph api results authenication error in iOS?

My iOS app is live and I have used Facebook Graph API for publishing the post but suddenly i am getting complain that post sharing gets fail.I have checked with facebook developer forum and they are talking about i need to add one more permission for that which i added but still i am getting same error.Here I am posting my code what i have did it for publishing on facebook wall.Please share some ideas on that.
if ( (self.fbGraph.accessToken == nil) || ([self.fbGraph.accessToken length] == 0) ) {
[self.fbGraph authenticateUserWithCallbackObject:self andSelector:#selector(fbGraphCallback:)andExtendedPermissions:#"email,publish_stream,public_profile,user_checkins,publish_actions,status_update,user_friends,read_stream,user_photos,friends_photos"];
}
else
{
if([self.fbGraph.accessToken length] > 0){
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
NSString *Header;
if(self.AutoMatedSahre==100){
Header=[NSString stringWithFormat:#"'%# is planning to use this offer'\n%#",[[self.shareDelegate.userdetails valueForKey:#"firstname"] capitalizedString],[self.dForDetail valueForKey:#"business_name"]];
}else{
Header=[self.dForDetail valueForKey:#"business_name"];
}
NSString *dealdesc=[NSString stringWithFormat:#"%# offer on ABC.\n %#.\n http://www.example.com/deal_summary.html?deal_id=%#",[self.dForDetail valueForKey:#"business_name"],[self.dForDetail valueForKey:#"deal_name"],[self.dForDetail valueForKey:#"id"]];
[variables setObject:dealdesc forKey:#"message"];
[variables setObject:Header forKey:#"name"];
[variables setObject:[self.dForDetail valueForKey:#"image_url"] forKey:#"link"];
FbGraphResponse *fb_graph_response = [self.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];
self.feedPostId = (NSString *)[facebook_response objectForKey:#"id"];
I am getting following Response:
postMeFeedButtonPressed: {"error":{"message":"(#200) The user hasn't
authorized the application to perform this
action","type":"OAuthException","code":200}}
You need to get approval from facebook by resubmitting or submitting your app with review again the permission is publish_action check facebook dev documentation about this particular permission and you will get the process needed for submitting for a review.
Here is the link

Facebook post on news feed and link behind the "name" of the post

I am posting a post on the current user feed with the following code:
NSMutableDictionary *postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"http://url.com/image.jpg", #"picture",
#"The title of the post on the feed", #"name",
#"Caption text", #"caption",
#"Description text", #"description", nil];
[self.facebook requestWithGraphPath:#"me/feed" andParams:postParams andHttpMethod:#"POST" andDelegate:nil];
It works great but I can't figure out how to setup the link behind the name of the post ("The title of the post on the feed"). For now the link looks like the following :
https://www.facebook.com/connect/uiserver.php?app_id=[MY_APP_ID]&method=permissions.request&redirect_uri=[THE_URL_OF_THE_PICTURE]&response_type=code&display=page&auth_referral=1
Is there a way to control this url easily? Thanks!
-- EDIT --
Here is a screenshot of a kind of post I want to create :
http://cl.ly/image/020D1z3S2L16.
The link behind the blue title "Je t'ai envoyé un défi dans Années 80" is really clean (just like http://itunes.apple.com/app/[APP_NAME]) and I'd like to do the same.
I believe this not an open graph action, just a basic post. Thanks
All parameters of the Facebook feed are outlined in the Graph API reference, https://developers.facebook.com/docs/reference/api/post/.
The relevant ones are "name", "caption", "description" or "message". Therefore, if whatever is the element you are referring to is not affected, you don't have control over it.
Hey Its very easy just try this code.
NSMutableDictionary *params = [NSMutableDictionary dictionary] ;
[params setObject:#"Test post" forKey:#"message"];
[params setObject:#"link" forKey:#"type"];
[params setObject:#"http://yoursite.com" forKey:#"link"];
[params setObject:#"Link description" forKey:#"description"];
// Make the request
[FBRequestConnection startWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
if(appDelegate.isLoggedInWithTwitter)
{
[self postMessage:_lblTitle.text];
}
else
{
[self toggleProgressHud:NO title:#"" message:#""];
NSLog(#"%#",[NSString stringWithFormat:#"result: %#", result]);
UIAlertView *alertMsg=[[UIAlertView alloc]initWithTitle:nil message:#"Shared Successfully" delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
alertMsg.tag=11;
alertMsg.delegate=self;
[alertMsg show];
}
// Link posted successfully to Facebook
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#",[NSString stringWithFormat:#"%#", error.description]);
[self toggleProgressHud:NO title:#"" message:#""];
[self handleAPICallError:error];
}
}];
And here is the result which you want
For now the link looks like the following :
https://www.facebook.com/connect/uiserver.php?app_id=…&method=permissions.request&…
That sounds like you’ve got Authenticated Referrals enabled in your app settings …?
That would explain, why the link points to the Facebook URL with a parameter method=permissions.request embedded.
If so, and that’s not what you want – then turn of Authenticated Referrals.
"xx shared a link" cannot be controlled through a post. Facebook is performing tons of A/B testing to decide what to display...

Post a message on Facebook wall using Graph API

I have used the Graph API, and have successfully logged in to Facebook and gotten the friends list.
Now I need to post a message on the wall. How?
use the url for posting on wall and use this method for post on wall
- (void)postToWall
{
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = #"Enter your message:";
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}"];
[dialog show];
}
You can also learn how to publish wall and other essential practice for iOS Facebook Development from the demo that official published by facebook "Hackbook for iOS"
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:1];
[variables setObject:#"this is a test message: postMeFeedButtonPressed" forKey:#"message"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"yourFriendFbID/feed" withPostVars:variables];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
[parser release];
if you want to post to your wall thought your FB app without showing a dialog you could do it like this
NSString *message = #"some text";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:message, #"message",nil];
[fb requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self]; //fb here is the FaceBook instance.
and for sure you will do that after the user login and authorized the permissions .

Facebook + iOS - post link without dialog

I am using facebook-ios-sdk in my iphone application
I am trying to post a link on facebook from my iphone application
NSLog(#"link..%#",[shareDict objectForKey:#"url"]);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[shareDict objectForKey:#"url"], #"link",nil];
[facebookObj requestWithMethodName:#"facebook.Stream.publish" andParams:params
andHttpMethod:#"POST" andDelegate:self];
it successfully posted as my application log
2011-03-30 13:10:02.128 myApp[1804:207] link..http://khabar.ndtv.com/Home.aspx
2011-03-30 13:10:04.064 myApp[1804:207] received response..https://api.facebook.com/method/facebook.Stream.publish
2011-03-30 13:10:04.066 myApp[1804:207] request didLoad.. . . API..thod/facebook.stream.publish
But link is not showing on facebook wall... it shown as..
Now
How I post the link with out showing dialog
How I it as like in facebook .. as user have option to select the image from link with out any dialog.. I can use my own view for it. like as
Here's my FB arguments snippet:
[fbArguments setObject:theName forKey:#"name"];
[fbArguments setObject:theCpation forKey:#"caption"];
[fbArguments setObject:theDescription forKey:#"description"];
[fbArguments setObject:theLink forKey:#"link"];
[fbArguments setObject:theHREF forKey:#"href"];
[fbArguments setObject:thePictureURL forKey:#"picture"];

Posting links to facebook wall from iPhone app

I am posting to the facebook wall from an iPhone app. It works well when I just sends a message, but when I try to add a link the message is not posted on Facebook.
Code:
NSString *link = #"http://www.foo.com";
NSString *linkName = #"Bar";
NSString *linkCaption = #"Foo Bar";
NSString *linkDescription = #"Fooooooo Bar";
NSString *message = #"Message";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, #"api_key",
message, #"message",
linkName, #"name",
linkDescription, #"description",
link, #"link",
linkCaption, #"caption",
nil];
[_facebook requestWithGraphPath: #"me/feed"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
It is when I add the link and caption to the params dictionary that FaceBook will not post on the wall. I don't even get an error in (void) request: (FBRequest *) request didFailWithError: (NSError *) error so it seems Facebook thinks the request is ok.
You may want to check out ShareKit. It's a pretty well-maintained open-source library for interfacing with the various social web services and leaves maintaining API compatibility with the ShareKit community.
I just posted the Link in FB with the use of attachment...
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
#"Visit My Site", #"name",
#"http://www.mysite.com", #"href", nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Your Message",#"message",
attachmentStr,#"attachment",nil];
For showing links on FB, u could make use of actionLinks.
delgates as
dialog.actionLinks = #"[{\"text\":\"See My App here!\",\"href\":\"http://www.facebook.com/developers/apps.php?app_id=178257532217623&ret=2/\"}]";
this will show ur links on right side of the post
I'm not sure what your problem is, since everything looks fine, but this might help you troubleshoot:
http://developers.facebook.com/docs/reference/rest/stream.publish/
Try posting your message via form on that page and see what Facebook tells you. If there is a problem, you'll see an error message.
To post a link you need to add an attachment with this syntax:
{ "href": "http://www.fantasy-fan.org", "name": "test", "caption": "test2", "description": "test3", "media": [{ "type": "image", "src": "http://dragontest.fantasy-fan.org/images/dwarf.jpg", "href": "http://www.fantasy-fan.org" }]}
If you are using FBConnect then use this methods every thing is post on FB wall.
- (void)postToWall
{
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = #"Enter your message:";
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}"];
[dialog show];
}
I had the same problem but with a PHP app and solved it by getting a page access token. Once you have a user access token go to:
https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
Within the returned data find the page's name and and its corresponding access token. Using the page access token allowed my links to be posted.
Use This.This one is working fine for me.
NSString *graphPath = #"me/feed";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.link,#"link",
self.url,#"picture",
self.message,#"name",
#"Write_Captioon",#"caption",
self.description,#"description",
/*#"Facebook Dialogs are so easy!",#"message",*/
nil];
[[FBRequestWrapper defaultManager] sendFBRequestWithGraphPath:graphPath params:params andDelegate:self];
Check your url too,may be that url is not of proper form.I didn't face this kind of problem in Facebook but in case LinkedIn when my url has "=",the post was not being shared,but was successfully sharing with other urls.Hope this will help you.

Resources