Issue with share only text on Facebook using FacebookSDK - ios

In my application i want to share only text on facebook. For that i am using FacebookSDK.
My Code for that is as below:
NSDictionary *params = #{
#"name" :[NSString stringWithFormat:#"Jinx Share"],
#"caption" : [NSString stringWithFormat:#""],
#"description" :#"Some text to share",
#"picture" : #"",
#"link" : #"",
};
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
{
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
else if(session.isOpen)
{
// Invoke the dialog
[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(#"Story published.");
}
}}];
}
}];
But when facebook share dialogue opens, it does not show any text there. Please see below screenshot
And if i gave any link in "picture" parameter then it shows the text. But i don't want any image to be shown. I just want only text to share on facebook.
What is wrong with my code ? Could someone give me solution.

Since the latest Facebook SDK from the month of April, Facebook does not allow your app to pre-fill any content to be shared. This is inconsistent with Facebook Platform Policy, see Facebook Platform Policy, 2.3. Also refer this Sharing through Facebook.

This API is deprecated to share the pre-selected text in native Share dialogue. You can use Graph API with custom story to share the pre-selected text:
Here is the link: https://developers.facebook.com/docs/sharing/opengraph/ios

Related

facebook content looks diffrent in wall and home page , after posting the content from iOS app using facebook sdk of iOS

Facebook content looks different in wall and home page , after posting the content from iOS app using facebook sdk of iOS,
Used Code : We are using following code for posting the data in facebook wall.
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Found this app ", #"message",
#"AppName", #"name",
#"App Title", #"caption",
#"Description data", #"description",
#"Link URL", #"link",
#"Image URL", #"picture",nil];
// create the connection object.
FBRequestConnection *newConnection = [[[FBRequestConnection alloc] initWithTimeout:kRequestTimeoutInterval] autorelease];
// create the request object, using the fbid as the graph path as an alternative the request* static methods of the
// FBRequest class could be used to fetch common requests, such as /me and /me/friends
FBRequest *request=[[[FBRequest alloc] initWithSession:activeSession
graphPath:#"me/feed"
parameters:params
HTTPMethod:#"POST"] autorelease];
Detail: When we are going to post this data and link url ia available then content are looks different in home screen and profile screen .
Instead od App Name is display the Link URL title in home page but in profile page it display right content like App Title.
It happen only posting from iOS app , it looks good from Android app.
Please help Me tikamchandrakar#gmail.com or tikam.chandrakar#xymob.com
Let me know if any thing is not clear.
Thanks
Try This code. It works Perfect for me -
// Helper method to request publish permissions and post.
- (void)requestPermissionAndPost {
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error && [FBSession.activeSession.permissions indexOfObject:#"publish_actions"] != NSNotFound) {
// Now have the permission
[self postOpenGraphAction];
} else if (error){
// Facebook SDK * error handling *
// if the operation is not user cancelled
if (error.fberrorCategory != FBErrorCategoryUserCancelled) {
// [self presentAlertForError:error];
}
}
}];
}
// Creates the Open Graph Action.
- (void)postOpenGraphAction {
NSString *pageId = #"";
if ([pageIdArray count] > 0) {
pageId = [[pageIdArray objectAtIndex:0] objectForKey:#"page_id"];
}else{
pageId = #"";
}
//http://mistoh.com/mistohws/CategoriesIcon/CategoryIcon_%1$s.png
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:#{
#"link":#"http://mistoh.com/mistohws/CategoriesIcon/CategoryIcon_1.png",
#"message":[NSString stringWithFormat:#"I just shared a Mistoh at %#",self.mistohNameStr],
#"place":[NSString stringWithFormat:#"%#",pageId],
#"name":[NSString stringWithFormat:#"%#",self.mistohNameStr],
#"description":[NSString stringWithFormat:#"%#",self.mistohDescStr],
#"address":[NSString stringWithFormat:#"%#",self.mistohAddressStr],
#"tags":[NSString stringWithFormat:#"%#",self.selectedFriendsStr]
}
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
//verify result
if (!error) {
[[[UIAlertView alloc] initWithTitle:#"Shared Mistoh Successfully!!"
message:#""
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
}else{
[[[UIAlertView alloc] initWithTitle:#"Error"
message:#"Error while sharing mistoh with friends."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
NSLog(#"Error : %#",[error description]);
}
}];
}
It looks good on facebook wall and timeline. Thank You..

The permission of Facebook post is "Only me" using FBWebDialogs

I want to post text and link from iOS app to user timeline. I copy and paste FBWebDialogs example.
Problem 1:
The post appear in my timeline but the permission is "Only me", not friend or public.
Problem 2:
The result object (FBWebDialogResult) is nil. Log appear in my console.NSLog(#"User canceled story publishing.");
Problem 3:
The permission of preview box is "only me" even I set it to public
Attached setting of my Facebook page:
Here is my code:
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or publishing a story.
NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled story publishing.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
NSLog(#"User canceled story publishing.");
} else {
NSString *msg = [NSString stringWithFormat:
#"Posted story, id: %#",
[urlParams valueForKey:#"post_id"]];
[[[UIAlertView alloc] initWithTitle:#"Result"
message:msg
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}
}
}
}];
The setting page of my app is "only me" by default. I don't expect all my users change this setting here.
OMG. I stuggled for whole day but no progress. I found solution as soon as I ask question.
The problem is I copied inappropriate sample code. Ichanged to [FBSession openActiveSessionWithPublishPermissions] and problem solved.
Here is the login code I used. My post can be public now.
- (void)buttonRequestClickHandler:(id)sender {
// FBSample logic
// Check to see whether we have already opened a session.
if (FBSession.activeSession.isOpen) {
// login is integrated with the send button -- so if open, we send
// [self sendRequests];
NSLog(#"Login in facebook");
} else {
NSArray *permission = [NSArray arrayWithObjects:#"publish_actions", nil];
[FBSession openActiveSessionWithPublishPermissions:permission defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
// if otherwise we check to see if the session is open, an alternative to
// to the FB_ISSESSIONOPENWITHSTATE helper-macro would be to check the isOpen
// property of the session object; the macros are useful, however, for more
// detailed state checking for FBSession objects
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
// send our requests if we successfully logged in
NSLog(#"Login in facebook"); }
}];
}

nil resultURL after successfully posting with FBWebDialogs (Facebook SDK 3.5)

I'm integrating Facebook on my application to share links of websites. I'm using the Feed Dialog to accomplish this and I'm following this tutorial:
https://developers.facebook.com/docs/howtos/feed-dialog-using-ios-sdk/.
I've managed to login and post to Facebook but I wanted to add a message when the post was successful. The tutorial has this built in, but every time I post, I see "User canceled story publishing." in the Log which is the message that is displayed when the user clicks on cancel. Besides I've confirmed with the debugger that the param resultURL received by the handler is always nil even on successful posts.
At first I though it was a configuration issue in my Facebook App, but I decided to make a test. I opened the RPSSample that comes with the framework, added a completion handler to the presentRequestsDialogModallyWithSession call in the clickInviteFriends method in the RPSFriendsViewController.m view controller and I was getting a nil resultURL on successful posts there too.
I'm I missing something?
I know the 3.5 SDK version is very new, but according to the documentation I should be getting a valid resultURL param after posting through a Facebook Web Dialog so I'm not sure if it's a bug or if I'm missing some callback or handler somewhere.
Just in case, this is my call to the Feed Web Dialog. It has minor changes compared to the one that comes in the tutorial (it's actually simpler)
- (void)publish: (EntityToShare *)entityToShare {
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
entityToShare.link, #"link",
nil];
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or publishing a story.
NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled story publishing.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User clicked the Cancel button
NSLog(#"User canceled story publishing.");
} else {
// User clicked the Share button
NSString *msg = [NSString stringWithFormat:
#"Posted story, id: %#",
[urlParams valueForKey:#"post_id"]];
NSLog(#"%#", msg);
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:msg
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}
}
}
}];
}
We have a fix for this in place and will be pushed out soon.
Edited:
This has now been fixed in the SDK release 3.5.1
Check it out here: https://developers.facebook.com/ios/

iOS Facebook Posing Photo, URL, Message and Name

I'm trying to post Photo, URL, message and name to Facebook from my iOS application to user's wall. I'm using latest Facebook framework 3.1
I'm using following code:
NSDictionary* dict = #{
#"link" : #"https://www.yahoo.com",
#"picture" : UIImagePNGRepresentation([UIImage imageNamed:#"Default.png"]),
#"message":#"Your message here",
#"name" : prodName,
#"caption" : [NSString stringWithFormat:#"Try the app: %#", prodName],
#"description" : #"Integrating Facebook in ios"
};
[FBRequestConnection startWithGraphPath:#"me/photos" parameters:dict HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSString *alertText;
if (error)
{
NSLog(#"%#",[NSString stringWithFormat: #"error: domain = %#, code = %d", error.domain, error.code]);
alertText = #"Failed to post to Facebook, try again";
} else
{
alertText = #"Posted successfully to Facebook";
}
[[[UIAlertView alloc] initWithTitle:#"Facebook Result" message:alertText delegate:nil cancelButtonTitle:#"OK!" otherButtonTitles:nil] show];
}];
I'm able to post successfully. But I'm seeing in Facebook that, its posting only photo and message and not other details. If I'm using #"me/feed", I'm not even able to post successfully. Facebook is giving error code=5.
How can I post all the details?
"me/feed" requires a url for the "picture" parameter. Please take a look at this link: a previous post on posting a photo on user's wall
Looks like you have to decide whether to use "me/photos" or "me/feed". This link will give you more information and may be a possible way around it.

Errors when posting to a friends feed using FB iOS SDK

Some form of this has been asked/answered before but I'm still pretty hazy on the issue. I'm trying to post to a friends feed but keep getting "error com.facebook.sdk code = 5" errors when trying to use startWithGraphPath: from the new FB SDK for ios. The FBSession is active and open and the access_token appears to be correct... Here's some code:
-(void)inviteUser:(NSString *)whoever {
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound) {
// No permissions found in session, so ask for it
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:#"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error) {
if (!error){
[self sendInvite:whoever];
}
}
}];
}
-(void) sendInvite:(NSString *)whoever {
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"A name of something", #"name",
nil];
[FBRequestConnection
startWithGraphPath:[NSString stringWithFormat:#"%#/feed", whoever]
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 = #"Posted successfully.";
}
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}];
I'm still new at this, and am probably missing something basic. But I'm just not seeing it.
Fixed it. I think there were two problems:
Not having the session properly communicated inside the app (i.e. I had the FBSession open in a loginController, but not in the sendInvite controller <- not the exact names, obviously). As a result, the access_token actually wasn't active. I should have followed the FB docs and put the FBSession methods in the appdelegate.
I was using "publish_action" permissions when I believe I should have been using "publish_stream."
Works smoothly with these two changes. I do have a follow-up question, though: how to post on someone else's wall using the new SDK's native share dialog? I'll probably ask this as a separate question.

Resources