How to share multiple post on friend's wall in objective C - ios

I'm using facebook sdk to post on friend's wall. I am able to post it but when i select multiple friends in FBWebDialog instead of posting two friends simultaneously for each friend a separate dialog box is shown. How to post on multiple friend's wall .
-(void)showFriendsList
{
friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = #"Pick Friends";
friendPickerController.delegate = self;
[friendPickerController loadData];
}
-(IBAction)facebookShare:(UIButton *)sender
{
[friendPickerController presentModallyFromViewController:self animated:YES handler:
^(FBViewController *sender, BOOL donePressed) {
if (!donePressed)
{
return;
}
NSString* fid;
NSString* fbUserName;
for (id<FBGraphUser> user in friendPickerController.selection)
{
NSLog(#"\nuser=%#\n", user);
fid = user.id;
fbUserName = user.name;
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:remedyLabel, #"caption", appIcon, #"picture",symptomName, #"name",remedyDescription,#"description",fid,#"tags",fid,#"to",#"106377336067638",#"place", nil];
NSLog(#"\nparams=%#\n", params);
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed",fid] parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection,id result,NSError *error)
{
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
NSLog(#"Error publishing story.");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled story publishing.");
}
else
{
// Handle the publish feed callback
//Tell the user that it worked.
NSLog(#"Request Sent");
}
}
}];
}];
}
}];
}

No, that's not possible. You have to open separate dialog for each friend.

Related

Sending facebook friend request invite returns the message: User canceled request

i am using this code , to send Invite friend request for facebook freinds,this code give the message is User canceled request.
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
// NSLog(#"%#", result);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:#"%#", result], #"to", #"send", #"action_type", #"YOUR_OBJECT_ID", #"object_id", nil];
//for (NSDictionary *params in [result objectForKey:#"data"])
{
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Learn how to make your iOS apps social."
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
// Handle the send request callback
NSDictionary *urlParams = [appDelegate parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"request"]) {
// User clicked the Cancel button
NSLog(#"User canceled request.");
} else {
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:#"request"];
NSLog(#"Request ID: %#", requestID);
}
}
}
}];
}
}];
Please check by adding only the following code and removing the block above this code.
[FBWebDialogs
presentRequestsDialogModallyWithSession: nil
message:#"Your invite message"
title:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error publishing story: %#", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User canceled.
NSLog(#"User cancelled.");
} else {
// Handle the publish feed callback
}
}
}];

Why my dialogue box login of the Facebook integration isn't supported?

In my App, I've created Facebook Integration when I click on Facebook login it goes to Safari browser, how can change it to dialogue box login without entering via Safari web browser?
Thanks In Advance.
[FBSession.activeSession closeAndClearTokenInformation];
if (FBSession.activeSession.accessTokenData.loginType != FBSessionLoginTypeFacebookApplication /||
FBSession.activeSession.accessTokenData.loginType !=
FBSessionLoginTypeSystemAccount/) {
[HUD hide:YES];
HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
HUD.labelText = #"Signing In";
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info",#"email",#"user_location",#"user_birthday",#"user_hometown,user_friends"]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
switch (state) {
case FBSessionStateOpen:{
[FBSession setActiveSession:session];
[self checkSessionState:state];
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection
*connection, NSDictionary *user, NSError *error) {
if (error) {
[HUD hide:YES];
NSLog(#"error Report :%#",error);
}
else
{
[HUD hide:YES];
NSString *userLocation = [NSString stringWithFormat:#"%#\n\n",user.location[#"name"]];
NSArray* foo = [userLocation componentsSeparatedByString: #","];
NSString *strCity = [foo objectAtIndex: 0];
NSString *strState = [foo objectAtIndex: 1];
NSString *linkURL = [NSString stringWithFormat:#"http://carzillaapp.com/"];
NSString *pictureURL = #"http://www.friendsmash.com/images/logo_large.jpg";
// NSString *pictureURL = #" ";
// Prepare the native share dialog parameters
FBShareDialogParams *shareParams = [[FBShareDialogParams alloc] init];
shareParams.link = [NSURL URLWithString:linkURL];
shareParams.name = #"Download and Checkout CarZilla App!";
shareParams.caption= #"An online Car Showroom!";
shareParams.picture= [NSURL URLWithString:pictureURL];
shareParams.description =
[NSString stringWithFormat:#"Both new and old cars available there!"];
if ([FBDialogs canPresentShareDialogWithParams:shareParams]){
[FBDialogs presentShareDialogWithParams:shareParams
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error publishing story.");
} else if (results[#"completionGesture"] &&
[results[#"completionGesture"] isEqualToString:#"cancel"]) {
NSLog(#"User canceled story publishing.");
} else {
NSLog(#"Story published.");
}
}];
} else {
// Prepare the web dialog parameters
NSDictionary *params = #{
#"name" : shareParams.name,
#"caption" : shareParams.caption,
#"description" : shareParams.description,
#"picture" : pictureURL,
#"link" : linkURL
};
// 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.");
}
}}];
}
NSDictionary *params = #{
#"name" : shareParams.name,
#"caption" : shareParams.caption,
#"description" : shareParams.description,
#"picture" : pictureURL,
#"link" : linkURL
};
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:#"Checkout the CarZilla App!"]
title:#"Invite"
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error) {
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
NSLog(#"Request Sent.");
}
}}
];
SignUpViewController *faceblogin = [[SignUpViewController alloc]init];
faceblogin.firstName = [NSString stringWithFormat:#"%# ",user.first_name];
faceblogin.lastName = user.last_name;
faceblogin.email =[user objectForKey:#"email"];
faceblogin.city = strCity;
faceblogin.state = strState;
faceblogin.fblogin = YES;
fbFailure = YES;
fbMsg = YES;
faceblogin.accountType = #"Individual Buyer/Seller";
//faceblogin.isPhoneno = YES;
[self presentViewController:faceblogin animated:YES completion:nil];
}
}];
break;
}
case FBSessionStateClosed:{
[HUD hide:YES];
NSLog(#"facebook values");
}
case FBSessionStateClosedLoginFailed:{
[HUD hide:YES];
if ((!fbFailure && fbMsg) || error.code == 2) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Unfortunately, we
were not able to log you in using your Facebook credentials."
delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
fbMsg = NO;
[alert show];
}
[FBSession.activeSession closeAndClearTokenInformation];
break;
}
default:
break;
}
} ];
}
else{
NSLog(#"accounts"); }

Not sending facebook game request/invite

I'm trying to implement Game Request/Invite. Facebook is not returning any errors and I can share status in the user timeline using the same game/app configuration.
This is my code:
// -----------------------------------------------------------------------
//Facebook login
// -----------------------------------------------------------------------
- (void)fbLoginClicked:(id)sender
{
NSLog(#"-------------------------fbButtonClicked--------------------");
[[NSNotificationCenter defaultCenter] postNotificationName:#"LoginFaceBook" object:nil];
if (!FBSession.activeSession.isOpen) {
// 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) {
NSLog(#"error");
NSLog(#"message error %#", error.localizedDescription);
} else if (session.isOpen) {
NSLog(#"session is open");
[self pickFriendsButtonClick:sender];
//[self inviteFriends];
//[self publishResult];
//[self publishButtonAction];
NSLog(#"pick Friends button on click");
}
}];
}
}
// -----------------------------------------------------------------------
//Facebook pick friends
// -----------------------------------------------------------------------
- (void)pickFriendsButtonClick:(id)sender {
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:#"I just smashed %d friends! Can you beat it?", score]
title:#"Smashing!"
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
NSLog(#"Request Sent.");
}
}}
friendCache:nil];
}
I already checked my app settings in Facebook.
My Bundle ID is the same in my plist and I also have input my iPhone Store ID from AppStore.
And this is my code for share status on timeline, which is working great:
// -----------------------------------------------------------------------
//Share in Facebook
// -----------------------------------------------------------------------
- (void)publishResult {
// We want to upload a photo representing the gesture the player threw, and use it as the
// image for our game OG object. But we optimize this and only upload one instance per session.
// So if we already have the image URL, we use it, otherwise we'll initiate an upload and
// publish the result once it finishes.
NSLog(#"sharing operations starting");
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
NSMutableDictionary<FBOpenGraphObject> *game = [FBGraphObject openGraphObjectForPost];
game[#"type"] = #"fb_sample_rps:game";
game[#"title"] = #"an awesome game of Rock, Paper, Scissors";
game[#"data"][#"player_gesture"] = #"scissor";
game[#"data"][#"opponent_gesture"] = #"paper";
game[#"data"][#"result"] = #"win";
game[#"image"] = #"http://sandbox.yoyogames.com/extras/image/name/san2/853/404853/original/Game1.jpg";
NSLog(#"game object created");
FBRequest *objectRequest = [FBRequest requestForPostOpenGraphObject:game];
[connection addRequest:objectRequest
completionHandler:^(FBRequestConnection *innerConnection, id result, NSError *error) {
if (error) {
NSLog(#"tried to share, but Error: %#", error.description);
} else {
NSLog(#"message posted");
}
}
batchEntryName:#"objectCreate"];
NSString *message = #"teste 2";
[connection addRequest:[FBRequest requestForPostStatusUpdate:message]
completionHandler:^(FBRequestConnection *innerConnection, id result, NSError *error) {
NSLog(#"Error on post update feed");
}];
[connection start];
}
Already solved.
For some reason, my friend's Facebook version is an old one and don't receive any messages. For other friends with updated Facebook layout, it's working.

presentFeedDialogModallywithSession does not post message to a friend

Iam using the following code to post a message on my friend's facebook wall. This code posts message to the logged in users wall but not to the friend's wall
Iam also giving the "to" value and i.e., friends facebook id (116623456) and App_id but same problem persists.
Please provide a good direction on this.
- (void)facebookViewControllerDoneWasPressed:(id)sender
{
NSLog(#"DonePressed Called");
NSString* fid;
NSString* fbUserName;
NSString *message = [NSString stringWithFormat:#"You have been selected as a health coach(Multiple Users1), You will be receiving daily and weekly reports from here on!!!!"];
NSLog(#"Before For");
// NSString *SelectedFriends = nil;
for (id<FBGraphUser> user in _friendPickerController.selection)
{
fid = user.id;
fbUserName = user.name;
NSLog(#"User Name =%#, USer id =%#",fbUserName, fid);
}
NSLog(#"After For");
NSLog(#"%#",fid);
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"4444444444444444",#"app_id",
fid,#"to",
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
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:#"Message Posted Successfully"
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}
}
}
}];
}
- (void)facebookViewControllerDoneWasPressed:(id)sender {
NSMutableString *text = [[NSMutableString alloc] init];
// we pick up the users from the selection, and create a string that we use to update the text view
// at the bottom of the display; note that self.selection is a property inherited from our base class
for (id<FBGraphUser> user in self.friendPickerController.selection) {
if ([text length]) {
[text appendString:#", "];
}
[text appendString:user.name];
NSString *fid=user.id;
NSString *fbUserName=user.name;
NSLog(#"");
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:#"Test miLineup!", #"message", #"Iphone Apps", #"name", nil];
NSLog(#"\nparams=%#\n", params);
//Post to friend's wall.
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed", fid] parameters:params HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
//Tell the user that it worked.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Shared"
message:[NSString stringWithFormat:#"Invited %#! error=%#", fbUserName, error]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
];
//Close the friend picker.
//[self dismissModalViewControllerAnimated:YES];
}

Facebook SDK for iOS 6.0 native Share dialog

I've include the Facebook native Share dialog in my iOS app to let users share some data. The problem is, that the dialog does not open. Here is the code. Also, it is normal for me to pass URL of image to the method? Maybe, this is the problem?
BOOL displayedNativeDialog =
[FBNativeDialogs
presentShareDialogModallyFrom:self
initialText:activityName
image:activityImageURL
url:activityURL
handler:^(FBNativeDialogResult result, NSError *error) {
if (error) {
NSLOG(#"Error occured");
} else {
if (result == FBNativeDialogResultSucceeded) {
NSLOG(#"Success");
} else {
NSLOG(#"No success");
}
}
}];
if (!displayedNativeDialog) {
NSLOG("Window does notdisplayed");
}
Instead of
image:activityImageURL
pass the UIImage data to image
image:[UIImage imageWithNamed:#"blahblah"]
You can use Native Dialogs only when the user has the Facebook App installed. First check if the facebook app is available, then either display the native dialog or display the web dialog accordingly:
FBShareDialogParams *shareParams = [[FBShareDialogParams alloc] init];
shareParams.link = [NSURL URLWithString:#"http://some-url.com"];
shareParams.name = #"Post Name";
shareParams.picture= [NSURL URLWithString:someImageURL];
shareParams.description = #"Post Description";
if ([FBDialogs canPresentShareDialogWithParams:shareParams])
{
[FBDialogs presentShareDialogWithParams:shareParams
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
NSLog(#"%#", [error localizedDescription]);
}];
}
else
{
NSDictionary *params = #{
#"name" : shareParams.name,
#"description" : shareParams.description,
#"picture" : objectiveCharacterImageURL,
#"link" : linkURL
};
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
}];
}

Resources