Today I started to use Facebook SDK 3.0 for iOS and I realized that there is no FBDialog class anymore. I've searched developers.facebook.com for some tutorials how I can show feed dialog using new sdk.
We used to write:
[facebook dialog:#"feed" andParams:params andDelegate:self];
But, it seems that all tips talking about dialogs are related to old SDK in developers.facebook.com.
Did anybody implemented feed dialog with new SDK?
Or, should we build our own DialogViewController to represent all UI elements as textFields, send button in order to make FBRequest?!
I've found the answer here:
Feed Dialog - Facebook Developers
Using the same new SDK 3.x we must add deprecated headers into Frameworks:
and change:
#import <FacebookSDK/FacebookSDK.h>
to
#import "Facebook.h"
EDIT (26.02.2013):
Thanks to Andreas, he mentioned in comment, using new SDK 3.2 doesn't required you include deprecated classes anymore:
Improved Web dialog support: This release adds support for integrating
Web dialogs, feed dialog, and requests dialog, without invoking
deprecated headers, making it cleaner and easier to add dialogs into
your app.
Example:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"", #"name",
#"", #"caption",
#"", #"description",
#"https://website.com/share", #"link",
#"http://website.com/iossdk_logo.png", #"picture",
nil];
[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
}
}
}];
With Facebook SDK 3.2, you don't need to import deprecated headers anymore. Web-based dialogs can be presented using the FBWebDialogs class:
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
// ...
}];
Related
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
I am working on ios application where I have to implement facebook publish/share feature. what I have done for sharing is
1: if user is not logged in, I am checking with this
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded||FBSession.activeSession.state == FBSessionStateOpen) {
//NSLog(#"Open");
//Set already opened session to FBSession
[FBSession setActiveSession:appDelegate.session];
//if user logged in already, perform sharing on fb
[self sharePostOnFb];
}else{
//if user is not logged in
[self openFbLogin];
}
-(void)openFbLogin
{
[FBSession openActiveSessionWithReadPermissions:#[#"public_profile", #"email",#"publish_actions"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
// Retrieve the app delegate
//AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
// Call the app delegate's sessionStateChanged:state:error method to handle session state changes
//[appDelegate sessionStateChanged:session state:state error:error];
if (state == FBSessionStateOpen) {
NSLog(#"opened");
[self sharePostOnFb];
}
}];
}
-(void)sharePostOnFb
{
NSString *strBznsName = [[[Global sharedInstance]getBznsInfo] objectForKey:#"name"];
NSString *strUserReceive = [NSString stringWithFormat:#"%# %# received %#.",[[[Global sharedInstance]getUserData] objectForKey:#"firstname"],[[[Global sharedInstance]getUserData] objectForKey:#"lastname"],dataStampDeal.strDealTerms];
NSString *urlLogoBkString= #URL_BZNSImgPath;
NSURL *urlLogoBkImage = [NSURL URLWithString:[NSString stringWithFormat:#"%#/%#",urlLogoBkString,[[[Global sharedInstance]getBznsInfo] objectForKey:#"logo" ]]];
NSString *StrUrl = [NSString stringWithFormat:#"%#",urlLogoBkImage];
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
strBznsName, #"name",
#"Powered By Anyloyalty", #"caption",
strUserReceive, #"description",
StrUrl, #"picture",
nil];
// Make the request
[FBRequestConnection startWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Link posted successfully to Facebook
NSLog(#"result: %#", result);
strFbPostId = [result valueForKey:#"id"];
NSLog(#"post id: %#", strFbPostId);
//[self WebServiceHandler:NO];
//[appDelegate startanimation];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#", error.description );
NSDictionary *errorInformation = [[[[error userInfo] objectForKey:#"com.facebook.sdk:ParsedJSONResponseKey"]
objectForKey:#"body"]
objectForKey:#"error"];
//NSLog(#"%#", errorInformation );
//__block NSString *alertText = #"Your action will not be published to Facebook.";
__block NSString *alertText = [errorInformation valueForKey:#"message"];
[[[UIAlertView alloc] initWithTitle:#"error"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
}
}];
}
facebook login (-(void)openFbLogin()) is opening web dialog. After successfully logged in. I am sharing post ( -(void)sharePostOnFb()) on fb and I am getting error
"(#200) The user hasn't authorized the application to perform this action"
For publishing/sharing I have to get approval for "publish_actions" permission from FB. I have submitted my application to FB app developer center. I am getting this message.
"Your app must not use a Facebook Web Dialog. Utilize our native Facebook Login SDK for iOS, so that users do not need to login twice."
so Now I want to "what is native Facebook Login SDK for iOS"? and how can I integrate that with my app?
The native Facebook login is nothing but using the iOS FB framework and create login using that. It is clearly mentioned on the developers.facebook.com how to login using there framework. You can also see the samples provided by them for login.
What this actually does is that , it check if the user has a Facebook application installed in the device and is user logged in to the Facebook app. If user is already logged in then user won't be asked to log in again. If user isn't logged in then they will be redirected to safari where they will have to log in to FB.
Its quite simple to integrate. Its well explained.
Facebook clearly says,
All iOS and Android apps should use their SDK's for iOS and Android for requesting permissions. Other apps should use their JavaScript for requesting permissions wherever possible.
Native applications on iOS and Android especially should use their SDK flows as they are optimized and work robustly across various types of devices without any manual adjustment.
In particular, their native SDKs let people who are already logged in to their Facebook app grant permissions without having to log in to their Facebook accounts again. This will result in far better conversion than not using our SDK and rendering our login dialogs inside web views embedded within your native app since the web view will not have any Facebook session data initially and will require people to login to their Facebook account.
Please note: if you are using Apple's Social framework, you may continue to do so, but ensure that if the user is not using the iOS integration, that your app falls back to the Facebook SDK for iOS. This can create more work than necessary, though, so we highly recommend using their SDK instead.
Here are the SDK implementation details:Facebook Login SDK for iOS
Deep Links
iOS allows apps to open other apps through a framework of custom URL
schemes. Integrating with Facebook allows users to the navigate
directly to your app from the Facebook app via these URLs, which we
will refer to as "deep linking". For example, when your app posts to
Facebook on behalf of its users, it can include one of these URLs, or
deep links, in the post. Then, when the user's friends engage with the
post and they are directed to your app, you will receive this link and
you can process it to decide what view to land them on.
I can share "normal" links from my test app from the iPhone Simulator. Now I want to share deep links from the iPhone Simulator. But as soon as I change the code to use a deep link the sharing process fails.
The sharing works with this set of parameters (Note: The link is an ordinary URL):
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Sharing Tutorial", #"name",
#"Build great social apps and get more installs.", #"caption",
#"Allow your users to share stories on Facebook from your app using the iOS SDK.", #"description",
#"https://developers.facebook.com/docs/ios/share/", #"link",
#"http://i.imgur.com/g3Qc1HN.png", #"picture",
nil];
The sharing does not work with this set of parameters (Now the link is a deep link):
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Sharing Tutorial", #"name",
#"Build great social apps and get more installs.", #"caption",
#"Allow your users to share stories on Facebook from your app using the iOS SDK.", #"description",
#"fbAPPID://authorize#target_url=[MYURL]", #"link",
#"http://i.imgur.com/g3Qc1HN.png", #"picture",
nil];
This is the code I use to actually share the link:
[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([NSString stringWithFormat:#"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);
}
}
}
}];
This is the error I see when I try to share with the second set of parameters:
I get it just after providing my login credentials. That not very informative. I don't know where to look. Is it even possible to share deep links from the iPhone Simulator?
EDIT: Deep Links and Custom Schemes are documented Facebook App features. There is an optional field for an URL Scheme Suffix in the Facebook Apps Settings page.
I'm trying to send a comment using Facebook iOS SDK to my FB friends.
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[[_usersFB valueForKey:#"selectValue"] componentsJoinedByString:#","], #"to",
nil];
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Test Comment"
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or sending the request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
// Handle the send request callback
}
}
}];
I'm using FB SDK v3.5.3.
I see all the friends in the FBDialog but when I tap on the send button the callback returns no error assuming it worked but my selected friends hasn't received anything.
FYI - My FB app is not in sandbox mode.
Any pointers would be greatly appreciated.
Cheers
Make sure you open the facebook page or app in an iPhone device when you check if it worked.
The notifications will not appear on facebook on on desktop browsers, only on iPhones.
I hope it helps.
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.