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;
Related
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];
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"); }
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];
}
}}];
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
I am trying to implement the native Share dialog from Facebook in a sample application.
Seem to have some problem in doing so.
Things I have done so far:
Included the latest Facebook SDK
Included the AdSupport, Social, Account, Security and libsqlite3.dylib.
Added the sample code from Facebook.
Added -lsqlite3.0 -ObjC to Other Linker Flags as well
Added the app id to the plist
Added the FBUserSettingsViewResources bundle and FacebookSDKResources.bundle to the project
But I can't seem to share the URL. The share dialog doesn't even appear.
My code looks like this:
Viewcontroller.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
IBOutlet UIButton *buttonShare;
}
- (IBAction)shareButtonClicked:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#import <FacebookSDK/FacebookSDK.h>
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)shareButtonClicked:(id)sender
{
FBShareDialogParams *params = [[FBShareDialogParams alloc] init];
params.link = [NSURL URLWithString:#"https://developers.facebook.com/ios"];
params.picture = [NSURL URLWithString:#"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
params.name = #"Facebook SDK for iOS";
params.caption = #"Build great apps";
[FBDialogs presentShareDialogWithParams:params clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
}
#end
Not able to share the URL. Need some guidance on this.
- (IBAction)shareButtonClicked:(id)sender
{
// 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)
{
NSString *str_img = [NSString stringWithFormat:#"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
NSDictionary *params = #{
#"name" :[NSString stringWithFormat:#"Facebook SDK for iOS"],
#"caption" : #"Build great Apps",
#"description" :#"Welcome to iOS world",
#"picture" : str_img,
#"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];
}
}}];
}
}];
return;
}
Do you have Facebook App installed on your device? The Share dialog only works if you have the Facebook app installed.
From the Share dialog documentation :
Tip 1: What if people don't have the Facebook app installed?
The Share dialog can't be displayed if people don't have the Facebook app installed. Apps can detect this by calling [FBDialogs canPresentShareDialogWithParams:nil]; and may disable or hide a sharing button or fall back to the Feed dialog to share on the web. See the HelloFacebookSample included with the iOS SDK for an example.
From what I saw, iOS 6 will return NO for + canPresentShareDialogWithParams:. It only responds to + canPresentOSIntegratedShareDialogWithSession:. But I could be wrong here.
Anyways, this is how I do it -
1. For sharing links :
if ([FBDialogs canPresentShareDialogWithParams:nil]) {
NSURL* url = [NSURL URLWithString:link.url];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success");
}
}];
}
2.For OpenGraph calls :
id<FBGraphObject> pictureObject =
[FBGraphObject openGraphObjectForPostWithType:#"your_namespace:picture"
title:image.title
image:image.thumbnailUrl
url:image.url
description:#""];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:pictureObject forKey:#"picture"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"your_namespace:action_name"
previewPropertyName:#"picture"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success");
}
}];
Check out other ways to share on iOS here
Hope this helps.
This works for me:
NSString *url = #"myUrl";
FBLinkShareParams* params = [[FBLinkShareParams alloc]init];
params.link = [NSURL URLWithString:url];
if([FBDialogs canPresentShareDialogWithParams:params]){
[FBDialogs presentShareDialogWithLink: [NSURL URLWithString:url]
name: #"Name"
caption: #"Caption"
description: #"Description"
picture: nil
clientState: nil
handler: nil];
}
else{
[...]
}
- (IBAction)btn_facebook:(id)sender {
[self performSelector:#selector(fb_func) withObject:nil afterDelay:0.0];
}
-(void)fb_func
{
// 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)
{
NSString *str_link = #"";
NSLog(#"%#",str_link);
NSDictionary *params = #{
#"name" :#"name",
#"caption" : #"Description",
#"description" :#"test",
#"picture" : PostimageToPintresrAndFacebook,
#"link" : #"url",
};
// 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.");
}
}}];
}
}];
return;
}