Is it possible to share deep links from the iPhone Simulator? - 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.

Related

"Error occurred" facebook login in ios application

i have integrate the facebook sdk for post something on facebook.Its working for only single facebook-id which is used for integrating facebook it in my application, not working for other.
this is my code
-(IBAction)postOnFacebook:(id)sender {
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];
// 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);
}
}
}
}];
}
// A function for parsing URL parameters returned by the Feed Dialog.
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:#"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:#"="];
NSString *val =
[kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}
this meth
Error come when i use another id for login
You are using the publish_action permission which can be made availaible to all users only after approval from facebook.
Currently you might have created the facebook app in your account and with that account id you will be able to post to facebook. This is because of the reason that facebook gives all the permissions to users who are added as Developers/Testers in the App Dashboard.
You can add people to your app as Testers/Developers by following the steps as described below
You'll need to be an admin to give someone a role on your Page. If the person is your Facebook friend:
Go to your Page and tap More.
Tap Edit Settings > Page Roles.
Tap Add Person to Page. You may need to enter your password to continue.
Begin typing a friend's name and tap their name from the list that appears.
Tap to choose a role > Add.
If the person isn't your Facebook friend, you can log into Facebook from a computer and add them by entering their email address.
Depending on their settings, the person may receive a notification or an email when you give them a role.
These users who are added will have all the permission that you are requesting.
If you want the permissions to be availaible to everyone, your facebook app should be approved and for that you have to submit your app to facebook for review. The guidelines for facebook app submision can be found from the following link
https://developers.facebook.com/docs/apps/review
Hope this helps you
I'm not sure if I understood your question.
But, for what I'm seeing. If you have created app at facebook (to integrate with your iOS app) you have to use the facebook app ID only, presented at Facebook.
Or, if this error is because you are trying to login with another facebook account. This is happening probably because you did not publish your app yet (facebook app). So it's not available to everyone, but its ok because you probably don't want to make it available right now. So you just need to go to the left menu at Roles in your facebook app page and add test users (the account that you're trying to login) or add as administrator.

List out all Facebook friends in native invite dialogbox in iOS

i'm trying to invite facebook friends in ios. successfully i got the output also. I attached that output image also.
My Question is, here i can see the suggested friends list instead of display my all friends. but while am searching any of friends in search bar, then it display that search list. My code is,
NSString *MY_URL = [NSString stringWithFormat:#"xxxxxxxxxx://host"];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:#"Hi, Check out this app, You'll love it!" forKey:#"message"];
[params setObject:MY_URL forKey:#"link"];
[FBWebDialogs presentRequestsDialogModallyWithSession:FBSession.activeSession
message:#"Friends Invite"
title:#"xxxxxxxx"
parameters:params handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (!error) {
NSLog(#"Url : %#",resultURL);
NSLog(#"Result : %u",result);
NSDictionary *urlParams = [self 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);
}
}
else
{
NSLog(#"Error : %#",[error localizedDescription]);
}
}];
My point is how can i display all my friends in this invite list itself.
For Facebook Apps registered later than April 2014, you can not access to all friends unless you are implementing a game/canvas app. (if this is your case, you will need to use invitable_friends endpoint)
Otherwise, unfortunately, you will be able to only access users facebook friends who have already signedin to your app.
Note: Even if your app was created before April 2014, all friends will be useless after april 2015.
For more info in facebook developer
New features available in v2.0
Taggable Friends API: We've added a new endpoint called /me/taggable_friends that you can use in order to generate stories that have friends tagged in them, even those friends don't use your app. If you want to use the taggable friends API, your app will require review.
Invitable Friends API: We've added a new endpoint called /me/invitable_friends that you can use to generate a list of friends for someone to invite to your game through a custom interface. This API is only available to apps that are games on Facebook Canvas.

IOS: what is native "Facebook Login SDK for 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

iOS: Post on wall of Selected FB Friends using FBWebDialogs

I can post image to facebook friend's wall using FBWebDialogs.What am looking is how can i post image to multiple Friends...
Below is my code for single post
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",
#"100006771363037",#"to",
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 canceled.
NSLog(#"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User canceled.
NSLog(#"User cancelled.");
} else {
// User clicked the Share button
NSLog(#"fb web dialog result=====>%#",result);
NSString *result = [NSString stringWithFormat: #"Posted story, id: %#", [urlParams valueForKey:#"post_id"]];
NSLog(#"result %#", result);
}
}
}
}];
While adding friends profile_id's separated by comma in #"to" field getting error.Added screen shot in below
You cannot add multiple ids in the to parameter in a Feed Dialog. In fact there's no way to post a feed to multiple friends at once. You have to invoke the dialog for each of the friend separately.
According to documentation, to is:
The ID or username of the profile that this story will be published to. If this is unspecified, it defaults to the value of from.

iOS Facebook SDK 3.2.1 Feed post error

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.

Resources