Posting links to facebook wall from iPhone app - ios

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.

Related

iOS Facebook SDK 3.2.1 Feed post error

I am working on iOS App and it has a simple facebook sharing functionality, basically it allows you to share a link to this app by posting in feed.
I am using facebook SDK 3.2.1 this way:
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test tweet", #"name",
#"Test", #"description",
#"http://myapplink.com",
#"link",
#"http://myapppicture.com/picture.jpg",
#"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
} else {
NSLog(#"No error!");
}
}
}];
The problem is: when this code runs, it brings up facebook login dialog and after I log in, I see this error on screen: "An error occured. Please try again later".
There's nothing logged in console, but if i close this dialogs, it only logs "User canceled story publishing."
Application settings are very basic - I've setup everything just like facebook asked to do:
http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/
My question is: has anybody came across the same problem? what can be possible solution?
Thanks!
Now this was fairly simple and I feel kinda stupid :)
But anyway, I hope this will help anybody who will be in the same problem.
Generally, I solved the problem by adding one more key-value pair to my "params" dictionary - value #"my_facebook_app_id" for key #"app_id".
So the correct dictionary looks like:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"11111111", #"app_id",
#"Test tweet", #"name",
#"Test", #"description",
#"http://sometestsite", #"link",
#"http://site.com/testimage.jpg", #"picture",
nil];
Facebook SDK says that app_id key is "Required, but automatically specified by most SDKs" - and even though I provided my app_id via MyApp-Info.plist file, it seems like it was not automatically specified (or I did something wrong).
So if you have the same problem, try adding this #"app_id" key - this should help.

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...

Posting image does not show up on wall

I am using the Facebook IOS library. I am trying to post an image to the user's wall. I am able to upload the image to the application Album, but i can not get it to show up on the user's wall.
The application is granted the publish_stream permissions:
[self.facebook authorize: [NSArray arrayWithObject: #"publish_stream"]];
The image is posted with the following code:
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
UIImagePNGRepresentation(_image), #"source",
message, #"message", nil];
[self.facebook requestWithGraphPath: #"me/photos"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
This works great - the image end up in the app album on Facebook - now how do I get this image to show up on the user's wall?
Thanks
Greg

Why does Facebook iOS dialog for feed publish disappear after login?

I'm trying to use the Facebook iOS "feed" dialog call to allow my app's user to share something on their Facebook wall. When the facebook app is not installed, it attempts to let them authenticate within the app (presumably using a web view). The issue is that this dialog just disappears once they authenticate. I was expecting the web view to return to the "feed" sharing view.
How do I detect that they authenticated so that I can re-open the feed dialog?
I've added fbDidLogin to my app delegate, but it's not being called. (I wasn't sure if this would normally be called or not, but I read several people recommending this.)
SBJSON *jsonWriter = [SBJSON new];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"More Videos",#"name",#"http://www.example.com/",#"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test Caption", #"caption",
#"Test Description", #"description",
#"https://s3.amazonaws.com/example/images/test.png",
#"source",
self.video.blogLink, #"link",
#"01234567890123", #"app_id",
actionLinksStr, #"actions",
nil];
[delegate facebook].sessionDelegate = delegate;
[[delegate facebook] dialog:#"feed" andParams:params andDelegate:self];
It turns out the issue is the same as those reporting that the dialog disappears immediately for them. There is a bug in the Facebook SDK in regards to handling error -999, with the solution described in this comment on SO.
I finally realized I was having the same issue (albeit manifesting slightly differently), when I started listening to the FBDialogDelegate's method:
- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError *)error
The error description referenced the -999 error mentioned above, leading me to the answer. Luckily the code checked into github worked flawlessly. I just had to pull it into the SDK codebase and recompile the .a lib file, then include it into my project.
Did you implemented facebook protocol FBSession in your view controller ?
To detect that user is authenticated you have to call isSessionValid:
if (![[self.fbAppDelegate facebook] isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:#"publish_stream",#"create_event",#"offline_access", nil];
[[self.fbAppDelegate facebook] authorize:permissions];
}
and authorize inApp:
[self authorizeWithFBAppAuth:NO safariAuth:NO];

iOS Facebook cannot post on another user's wall

I am trying to make a post on another user's wall using another user using FBConnect. I am using the embedded method of the iOS Facebook API (that is, I am forcing the browser to appear inside my app, so I am not leaving the application at all). This method works for posting into the wall of the same user, but doesn't work on the wall of another user.
self.facebook = [[[Facebook alloc] initWithAppId:self.appID andDelegate:self] autorelease];
if ([self.facebook isSessionValid]) {
[self proceedToPost];
}else{
NSArray *permissions = [NSArray arrayWithObjects:#"publish_stream", #"email", #"read_stream", #"manage_pages", nil];
[self.facebook authorize:permissions];
}
- (void)proceedToPost
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: #"aName", #"name",
self.appID, #"app_id",
self.title, #"caption",
self.link, #"link",
#"animateURL", #"picture",
nil];
[params setObject:"my-user-profile-id" forKey:#"to"];
[self.facebook dialog:#"feed" andParams:params andDelegate:self];
}
The problem is that authorization is done as expected, but when trying to actually post, I see an error message in the embedded browser "cannot post to user's wall".
Can anyone help me with this?
Did you request the publish_stream permission from the extended permissions?
From the documentation about publish_stream permission:
Enables your app to post content, comments, and likes to a user's
stream and to the streams of the user's friends. With this permission,
you can publish content to a user's feed at any time, without
requiring offline_access. However, please note that Facebook
recommends a user-initiated sharing model.
http://developers.facebook.com/docs/reference/api/permissions/
You can request permissons like this:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"publish_stream",
nil];
[facebook authorize:permissions];
[permissions release];

Resources