Objective-C : Force Use of Facebook App for Login? - objective-c

I have been browsing StackOverflow and Facebook docs for hours, and still can't seem to find a way to force Facebook Login SDK to use the installed Facebook App rather than popping up Safari.
Below is my code
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
login.loginBehavior = FBSDKLoginBehaviorSystemAccount;
[login logInWithReadPermissions: #[#"public_profile", #"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
// custom logic
}];
Can someone help me out?

FBSDKLoginBehaviorSystemAccount seems to be for logging in using the iOS builtin accounts system, not for using the Facebook app.
Try FBSDKLoginBehaviorNative for using the app.
Also see: FBSDKLoginBehaviorSystemAccount not working

Related

Not getting the email from twitter using Fabric Twitter SDK

This seems to be age old question with no specific answers or solutions for it. I had my application whitelisted from twitter. Done all the things. Checked the request email from user box and used the following code
[[Twitter sharedInstance] startWithConsumerKey:#"FabricKey" consumerSecret:#"FabricSecretKey"];
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController *shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString *email, NSError *error) {
NSLog(#"Email %# | Error: %#", email, error);
}];
[self presentViewController:shareEmailViewController
animated:YES
completion:nil];
But still it is returning null. Why is this?? I even created the application in twitter developer portal. Please help me. Is twitter trying to be more over secure?? It is just pissing me out......

OSX ACAccountStore requestAccessToAccountsWithType... returning 'granted=No' and error=nil after denying permissions

I am trying to request access to my facebook account. The first time I ran this it went well and I saw the popup requesting permissions. The popup asked me to allow or deny. I chose to deny because I wanted to test that use case. Now I cannot figure out how to get it to allow access again. I have deleted the app from my facebook account and deleted my facebook account from my mac. I've also tried adding the property
#"auth_type": #"rerequest"
to the options dictionary. I get the same result no matter what.
As mentioned in the title, the error is nil and granted is False.
Thanks in advance.
ACAccountType* accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary* options = #{
ACFacebookAppIdKey: [[NSBundle mainBundle] objectForInfoDictionaryKey:#"FacebookAppID"],
ACFacebookPermissionsKey: #[#"public_profile", #"email", #"user_friends"],
};
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError* error)
{
if (granted)
{
ACAccount* account = [[accountStore accountsWithAccountType:accountType] lastObject];
macFacebookAccount = account;
}
else
{
NSLog(#"%#", error);
}
}];
I solved this: Facebook permission settings for an app are located under System Preferences > Security and Privacy. From there just click facebook and check the box next to your app

How to specify the app name user was using to post - (via app name) using SDK 3.1

Using the new Facebook SDK 3.1 and iOS 6 there are 2 (actually 3) ways to post.
(Seems the new trend is to have more options to make it more simple??) OMG!!
Here is one:
SLComposeViewController *fbPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbPost addURL:[NSURL URLWithString:href]];
[self presentViewController:fbPost animated:YES completion:nil];
And this is another way using native dialogs:
[FBNativeDialogs presentShareDialogModallyFrom:self
initialText: nil
image: nil
url: [NSURL URLWithString:href]
handler:^(FBNativeDialogResult result, NSError *error) {
if (error) {
}
else
{
switch (result) {
case FBNativeDialogResultSucceeded:
break;
case FBNativeDialogResultCancelled:
break;
case FBNativeDialogResultError:
break;
}
}
}];
We, developers, think this is cool because we give a nice functionality to the user and also because our app name appears in the post and that can make some promotion of the app.
The funny thing is that latest implementations are not allowing to specify the app name was posting, the name appears after 'via'.
I tried aswell using SLRequest:
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *fbType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
(options)[#"ACFacebookAppIdKey"] = kFacebookAppID;
(options)[#"ACFacebookPermissionsKey"] = #[#"publish_stream"];
(options)[#"ACFacebookAudienceKey"] = ACFacebookAudienceFriends;
[store requestAccessToAccountsWithType:fbType options:options completion:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *fbAccounts = [store accountsWithAccountType:fbType];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
(params)[#"link"] = href;
// (params)[#"picture"] = picture;
// (params)[#"name"] = name;
(params)[#"actions"] = #"{\"name\": \"Go Gabi\", \"link\": \"http://www.gogogabi.com\"}";
//Set twitter API call
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:#"https://www.facebook.com/dialog/feed"] parameters:params];
//Set account
[postRequest setAccount: [fbAccounts lastObject]];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if(error)
{
NSLog(#"%#", error.description);
}
else
{
NSLog(#"%#", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}
}];
} else {
}
}];
Unfortunatelly to share that name is not so trivial anymore, I wonder why and who was designing the new implementation...
I would appreciate to get some help on that, thanks in advance.
I try to make my questions funny because is soo boring spend time in so trivial topics...
When you use the SLComposeViewController, it's actually the system presenting to you their controller, and it's the user who sends using the post button. Therefore on Facebook it appears as "via iOS".
There's no way to change that.
Using the Facebook SDK 3.1, under the hood it is also using the iOS 6 native integration, so when you're calling the FBNativeDialogs, on iOS 6, it's using SLComposeViewController.
Facebook continued to develop their SDK because they provide a couple of nice modules to use "out of the box" - this includes friends list selector etc... But I believe the biggest reason for Facebook to continue supporting their SDK it for backward compatibility. Under the hood if you're not on iOS 6, it falls back to it's library, and if you are on iOS 6, it uses the system integration.
Facebook is a big thing, and now it's natively available a lot of developers will be using it, just like Twitter's integration last year. The problem of course is at that point the developer has the option to drop older iOS support, or... have a lot of duplicate code, in the sense that they will check for SLComposeViewController and if it's not available (iOS 5) then use the old Facebook SDK... You can imagine how this would become very messy very quickly.
So, the Facebook SDK (3.1) is using iOS system Facebook integration if available, or if not, it's own. In a nutshell, unless you really want the Facebook SDK goodies (friend picket to name one), and you're not planning on supporting iOS < 6 then you don't need to worry about their SDK, just use the Social framework.
So, back to your question, there are 3 ways to post to Facebook ? Actually taking into consideration what I mentioned, there are 2 ways in iOS 6: SLComposeViewController or, SLRequest. On older iOS versions, only 1: Facebook SDK.
Since the SLComposeViewController is owned by the system, not your app, it will always share as "via iOS".
On the other hand SLRequest will show your apps name. When you specify an account for your SLRequest, that account was acquired via the ACAccountStore as a result of passing in some options including ACFacebookAppIdKey, which will be used to determine your Facebook apps name to post onto the users feed as part of the post.
Hope this helps.

How to get share dialog box with parse.com and facebook 3.0 sdk

I can't seem to find information on how to open share dialog box with parse sdk which includes fb 3.0. I am able to login with facebook and actually found a way to post with out the dialog box but still would like to have the dialog box so that people can add comments and it comes out with the image on facebook. This is what i have so far.
#"publish_stream",#"publish_actions" allows me to publish with out the dialog box
logInController.facebookPermissions = [NSArray arrayWithObjects:#"user_about_me",#"friends_about_me",#"publish_stream",#"publish_actions", nil];
this is to publish
PF_FBRequest *request = [PF_FBRequest requestForPostStatusUpdate:[self.Excerpt objectForKey:#"text"]];
[request startWithCompletionHandler:^(PF_FBRequestConnection *connection, id result, NSError *error){
NSLog(#"error %#",error);
}];
I found the code to open the dialog box from facebook website but i am not sure how to get an instance of the PF_Facebook object so i can open the dialog box. I can try to do
PF_Facebook *fb = [[PF_Facebook alloc]initWithAppId:<#(NSString *)#> andDelegate:<#(id<PF_FBSessionDelegate>)#>;
but that doesn't seem to be right because i already initialize this in the appdelegate
//Update
I am able to get the dialog box using this code
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Facebook SDK for iOS", #"name",
#"Build great social apps and get more installs.", #"caption",
#"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", #"description",
#"https://developers.facebook.com/ios", #"link",
#"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png", #"picture",
nil];
//publishes text on facebook
PF_FBSession *session = [PFFacebookUtils session];
PF_Facebook *fb = [[PF_Facebook alloc]initWithAppId:session.appID andDelegate:nil];
[fb dialog:#"feed" andParams:params andDelegate:self];
But the problem is that the person gets the login page in the dialog box even though he is authenticated already in the app
Any suggestions would be greatly appreciated!
Thank You!
To set up a PF_Facebook object you need to also provide the access token and expiration date information as below:
PF_FBSession *session = [PFFacebookUtils session];
PF_Facebook *facebook = [[PF_Facebook alloc] initWithAppId:session.appID
andDelegate:nil];
// Store the Facebook session information
facebook.accessToken = session.accessToken;
facebook.expirationDate = session.expirationDate;
Rather than creating a new session, you can just use the "facebook" class method to get a configured PF_Facebook object
PF_Facebook *facebook = [PFFacebookUtils facebook];
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Check out this great app", #"message", nil]:
[facebook dialog:#"apprequests" andParams:parameters andDelegate:nil];

Mac OS X Facebook login failed - no stored remote_app_id for app

I am trying to use the new ACAccountStore capabilities on Mac OS X 10.8 to login via Facebook but I get an error:
The Facebook server could not fulfill this access request: no stored remote_app_id for app
When the code executes the requestAccessToAccountsWithType message it does prompt me for access to Facebook (which I allow) and I do have Facebook credentials stored in my Settings. I also have another code path for legacy versions of OS X which logs into Facebook using the WebView control. It does work with the same APP_ID. So I should have the app correctly setup in the Facebook developer settings. In there some other configuration that I'm missing? I search on the Internet for "remote_app_id" and I get the empty set.
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: FB_APP_ID, ACFacebookAppIdKey, [NSArray arrayWithObjects:#"email", nil], ACFacebookPermissionsKey, ACFacebookAudienceFriends, ACFacebookAudienceKey, nil];
[account requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accountList = [account accountsWithAccountType:accountType];
for (ACAccount *thisAccount in accountList) {
NSLog(#"Found account: %#", [thisAccount accountDescription]);
}
}
else {
NSLog(#"Not granted because: %#", [error localizedDescription]);
}
}];
useful note for iPhone devs: to exhibit this problem 100%:
Regarding the same issue on the iPhone (this page is the main google landing for that): The issue is this: on the iPhone, go to Settings, left menu Facebook, then on the right username/password - login to Facebook. So that's the "Settings Facebook Login". If the iPhone is in fact logged in to FB on the "Settings Facebook Login" then the problem will exhibit. If you explicitly log out on "Settings Facebook Login" (and indeed, perhaps uninstall the FacebookApp), the problem will not exhibit.
Looks like you have to set bundle ID of your iOS/OSX app in Facebook app settings (that fixed thing in my case)
Set the bundle ID on the Facebook web interface, and it will get updated right away.
Its position on the updated developer UI is below: