Send messages using Facebook API iOS - ios

I was wondering if it is possible to send direct Facebook messages from one user to another using Facebook's API on iOS. If not is there any work arounds, could I get permission from Facebook.
Thanks in advance.
Ben.

str_id = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"id"];
str_name = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"name"];
str_link = #"www.google.com";
NSDictionary *params = #{
#"name" : str_name,
#"caption" : #"",
#"description" : #"",
#"picture" : #"",
#"link" : str_link,
#"to":str_id,
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
NSLog(#"Story published.");
[self.indicator stopAnimating];
}
}}];
[self.indicator stopAnimating];

Related

Facebook share shows blank image on iOS but works fine on desktop

I am using AddThis from the following page: http://www.douglasstratton.com/Beaches/Amnesia/flypage.tpl.html
When sharing from the desktop, the image shares fine, but when sharing from iOS, the image is blank on the facebook wall.
Has anyone else had this issue?
You can share with this code.Only import #import <FacebookSDK/FacebookSDK.h>:-
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
APP_NAME, #"name",
self.strSerialName , #"caption",
modelObject.strChapterDescription, #"description",
#"", #"link",
modelObject.strChapterImage, #"picture",
nil];
// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
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 cancelled.
NSLog(#"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User cancelled.
NSLog(#"User cancelled.");
} else {
// User clicked the Share button
NSString *result = [NSString stringWithFormat: #"Posted story, id: %#", [urlParams valueForKey:#"post_id"]];
NSLog(#"result %#", result);
}
}
}
}];

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"); }

How to post on friend's wall using facebook sdk?

I am using facebook SDK 3.13 for posting on user's friends wall using fbwebdialogs. When i set params for this dialog it does not show them on dialog.
NSMutableDictionary *params=[NSMutableDictionary new];
FBSession *ses=[FBSession activeSession];
[params setValue:#"hello" forKey:#"caption"];
[params setValue:#"hello" forKey:#"decription"];
[params setValue:#"whats" forKey:#"name"];
[params setValue:#"http://i.imgur.com/g3Qc1HN.png" forKey:#"picture"];
[params setValue:#"http://www.dsvv.org" forKey:#"link"];
[FBWebDialogs presentFeedDialogModallyWithSession:ses parameters:params handler:^(FBWebDialogResult result,NSURL *url,NSError *error){
if (error) {
}
}];
}
it does not identify these link and produce an error. If someone who posted on user's friends wall please notify me regarding this.
str_link = #"www.google.com";
NSString *str_img = [NSString stringWithFormat:#"%#uploads/%#-5.jpg",app.Main_url,[Data_Dict objectForKey:#"deal_id"]];
//NSLog(#"%#",str_img);
NSDictionary *params = #{
#"name" : str_name,
#"caption" : #"",
#"description" : #"",
#"picture" : str_img,
#"link" : str_link,
#"to":str_id,
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
NSLog(#"Story published.");
[self.indicator stopAnimating];
}
}}];

Facebook invitation to my app not working

I used following code to invite a friend to my app:
NSString *facebookID = user.id;
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObject:facebookID forKey:#"to"];
NSString *message = #"SOME_MESSAGE";
NSString *title = #"TITLE";
FBSession *facebookSession = [PFFacebookUtils session]; //You may changed this if you are not using parse.com
[FBWebDialogs presentRequestsDialogModallyWithSession:facebookSession
message:message
title:title
parameters:params handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (!error) {
NSLog(#"Succees:%#",resultURL);
}
}]; }
Opens WebDialog as shown:
But I see no invitation on my profile. How do I get it done properly?
str_id = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"id"];
str_name = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"name"];
str_link = #"www.google.com";
NSDictionary *params = #{
#"name" : str_name,
#"caption" : #"",
#"description" : #"",
#"picture" : #"",
#"link" : str_link,
#"to":str_id,
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
NSLog(#"Story published.");
[self.indicator stopAnimating];
}
}}];
[self.indicator stopAnimating];
you didn't mention if the console printed "Success...." or not.
anyway, if the request is successfull users will see it only on fb mobile app

Post to friends wall using FBWebdialogs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I used below code to post on Facebook,entered all required details in Params dictionary and added in FBWebDialogs, but the post is not displaying in friend wall.
NSDictionary *params = #{
#"name" :[NSString stringWithFormat:#"%#",[Data_Dict objectForKey:#"name"]],
#"caption" : #"",
#"description" :[Data_Dict objectForKey:#"desc_title"],
#"picture" : str_link,
#"link" : #"",
};
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error)
{
//NSLog(#"Error publishing story.");
[self.indicator stopAnimating];
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
//NSLog(#"User canceled story publishing.");
}
else
{
//NSLog(#"Story published.");
}
}}];
}
}];
Expecting ideas to fix this issue.
[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)
{
//NSLog(#"%#",Data_Dict);
NSString *str_link = [NSString stringWithFormat:#"%#uploads/%#-5.jpg",app.Main_url,[Data_Dict objectForKey:#"deal_id"]];
//NSLog(#"%#",str_link);
NSDictionary *params = #{
#"name" :[NSString stringWithFormat:#"%#",[Data_Dict objectForKey:#"name"]],
#"caption" : #"",
#"description" :[Data_Dict objectForKey:#"desc_title"],
#"picture" : str_link,
#"link" : #"",
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
//NSLog(#"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
//NSLog(#"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
//NSLog(#"Story published.");
[self.indicator stopAnimating];
}
}}];
}
}];
[self.indicator stopAnimating];
return;

Resources