Facebook Login ask to install (iPhone) - iphone

I need help in the facebook login from Facebook-SDK-3.1 for iOS 6.I have used all the code of the Facebook sdksample code sessionLoginSample,I have used the WebView opening code in this and whenever i login from the new id ...it takes me to the below image link to install in my project .dont know what exactly it is...and if i do so and after that logout from the code ..and when I again press button to login , it automatically log-in without asking for the id and pssword``login page. and again again it automatically logs-in , even after logout./.can anyone help me why after being logout it ask stores the previous access token and password.
and code is
- (IBAction)buttonClickHandler:(id)sender {
AppDelegate* appDelegate = [[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {
[appDelegate.session closeAndClearTokenInformation];
} else {
if (appDelegate.session.state != FBSessionStateCreated) {
appDelegate.session = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:#"email", nil]];
}
[appDelegate.session openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
FBSession.activeSession = session;
[self updateView];
NSLog(#" state=%d",state);
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error) {
userInfo = #"";
userInfo = user.username;
NSLog(#"string %#", userInfo);
[self checkfacebook];
}];
}]; }
}

FB grants access to your app once the user logs in . If the user wants to modify the privileges he can do it by loggin into fb and changing permissions. You might want to look into oAuth for further details.

As u login through new emailid it has to install your app for them...so,its asking for different login..but again u login with the same it will not ask...the answer for ur 2nd question is....is u doing something to the server side...bcoz there might be a provision on the server which remember user for few hour or few days...so,check with server side..if not working with server...reply me back i will try to answer further...

Related

Unable to implement a custom Facebook login button for IOS

I am trying to create a custom login button for IOS 9,i have been following the Facebook's tutorial for doing so but when i button is clicked,i end up getting this error
libc++abi.dylib: terminate_handler unexpectedly threw an exception
I have been following this Facebook tutorial,only difference is i am using dispatch_async due to some reasons.
https://developers.facebook.com/docs/facebook-login/ios#loginkit
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray* Permissions = [[NSMutableArray alloc] init];
[Permissions addObject:#"email"];
[Permissions addObject:#"public_profile"];
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithReadPermissions:Permissions
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
NSLog(#"Process error");
}
else if (result.isCancelled)
{
NSLog(#"Cancelled");
}
else
{
NSLog(#"Logged in");
}
];
});
I have tried using Parse SDK's code too like so...
NSArray *permissionsArray = #[ #"user_about_me", #"user_relationships", #"user_birthday", #"user_location"];
[PFFacebookUtils logInInBackgroundWithReadPermissions:permissionsArray block:^(PFUser *user, NSError *error)
{
if (!user)
{
NSLog(#"Uh oh. The user cancelled the Facebook login.");
}
else if (user.isNew)
{
NSLog(#"User signed up and logged in through Facebook!");
}
else
{
NSLog(#"User logged in through Facebook!");
}
}];
But both the time,i end up getting the same error like as shown in the image below..
Error message image
Am i doing something wrong in app validation process?
Please help!
Thank you!
This is weird,after playing around in Xcode,i found that it is not able to get my appID and other settings from my plist even though it's there.After i programmatically set my app id using
[FBSDKSettings setAppID:#"appid"];
[FBSDKSettings setDisplayName:#"displayname"];
I was to able get rid of that error,but i am stuck at URLSchemes...i will recreate the project and try again!
Thank you!
It's working now and,i am able to get a login page,but after i get past the app login screen,i am getting a blank white screen with only a done button at th top right corner,when i click it,i get the log message that the user cancelled login.

After successfull login with FBSession reshowing login on opening another Fb page

I have used FBSession for authentication to my app natively and this is working fine, I am also getting the accesstoken.
But my problem is after that when i am loading the Client facebook page on webView by passing the specific URl it is showing the page successfully but its not loged in. Still i can see Join and Log in button on the top.
As i am already loged in then why to login again.
Friends give me some hint how to solve this.
Here is the code.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self updateView];
SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (!appDelegate.session.isOpen) {
// create a fresh session object
appDelegate.session = [[FBSession alloc] init];
// if we don't have a cached token, a call to open here would cause UX for login to
// occur; we don't want that to happen unless the user clicks the login button, and so
// we check here to make sure we have a token before calling open
if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
// even though we had a cached token, we need to login to make the session usable
[appDelegate.session openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// this handler is called back whether the login succeeds or fails; in the
// success case it will also be called back upon each state transition between
// session-open and session-close
[self updateView];
}];
NSArray *permissions1 = #[#"email"];
[appDelegate.session requestNewReadPermissions:permissions1
completionHandler:^(FBSession *session,
NSError *error)
{
// Handle new permissions callback
}];
}
}
}
// FBSample logic
// main helper method to update the UI to reflect the current state of the session.
- (void)updateView {
// get the app delegate, so that we can reference the session property
SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {
// valid account UI is shown whenever the session is open
[self.buttonLoginLogout setTitle:#"Log out" forState:UIControlStateNormal];
[self.textNoteOrLink setText:[NSString stringWithFormat:#"https://graph.facebook.com/me?access_token=%#",
appDelegate.session.accessTokenData.accessToken]];
NSLog(#"Print %#",self.textNoteOrLink.text);
// NSLog(#"Print the user name is %#",appDelegate.session.accessTokenData)
} else {
// login-needed account UI is shown whenever the session is closed
[self.buttonLoginLogout setTitle:#"Log in" forState:UIControlStateNormal];
[self.textNoteOrLink setText:#"Login to create a link to fetch account data"];
}
}
// FBSample logic
// handler for button click, logs sessions in or out
- (IBAction)buttonClickHandler:(id)sender {
// get the app delegate so that we can access the session property
SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {
// if a user logs out explicitly, we delete any cached token information, and next
// time they run the applicaiton they will be presented with log in UX again; most
// users will simply close the app or switch away, without logging out; this will
// cause the implicit cached-token login to occur on next launch of the application
[appDelegate.session closeAndClearTokenInformation];
} else {
if (appDelegate.session.state != FBSessionStateCreated) {
// Create a new, logged out session.
appDelegate.session = [[FBSession alloc] init];
}
// if the session isn't open, let's open it now and present the login UX to the user
[appDelegate.session openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// this handler is called back whether the login succeeds or fails; in the
// success case it will also be called back upon each state transition between
// session-open and session-close
[self updateView];
}];
}
}
And in another view controller i am opening the client page like this:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"https://www.facebook.com/abc"]]];

Facebook App Login: Is it possible to catch 'cancelButtonPressed' event?

Is it possible to catch event 'CancelButtonPressed' in Facebook App through facebook-ios-sdk authorization flow?
I use pretty old version of Facebook SDK for IOS and open session like this:
[_facebookSession openWithBehavior:FBSessionLoginBehaviorWithNoFallbackToWebView
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(#"this is FBSession State: %d",status);
NSLog(#"this is NSError: %#",error);
NSLog(#"create new session with permissions: %#",_facebookSession.permissions);
}];
I saw this question, but maybe something changed in Facebook IOS SDK?
Maybe somebody knows answer or good solution?
Thanks for help!
EDIT:
if ([_facebookSession state]==FBSessionStateCreatedOpening){
// if we call FBApp, facebook session will be in this state (createdOpening)
// and we need to check it and close, to recall FBApp
[_facebookSession closeAndClearTokenInformation];
// and now recrate session and open it ;)
_facebookSession = [[FBSession alloc] initWithAppID:kAppId
permissions:permissions
urlSchemeSuffix:nil
tokenCacheStrategy:[FBSessionTokenCachingStrategy defaultInstance]
];
//and reopen it like `[_facebookSession openWith... ];`
}

Close currentsession in Facebook login in xcode?

I m integrating Facebook login in my app.
I have a Log out button in my app.When user clicks Sign Out then Facebook's current session should be closed .Again if I click Login it should show Login screen of Facebook.
When Log out button is clicked:
appDelegate.fbEmail=nil;
if (FBSession.activeSession.isOpen) {
[appDelegate closeSession];
}
AppDelegate.m
-(void)closeSession
{
[[FBSession activeSession] close];
}
-(BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI{
NSArray *permissions=[[NSArray alloc]initWithObjects:#"email", nil];
return[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
After he clicks logout it changes to login.Now when login is clicked Login screen of facebook should appear..How to do it ?
Could you try FBSessionDelegate Methods? Inside FBSessionDelegate have methods to handle session. In this case, i think you can use this function to handle you question :
- (void)fbDidlogout
{
// your code to get login screen here!
}
This function will called when the request logout has succeeded. Hope this will help, Cheers

How to login just in time to facebook in iOS app

Have reviewed the facbook pages on how to integrate facebook with iOS, but what i had been looking for is a bit different.
I would like to prompt for Facbook login only when a user decides to share stuff, the flow explained in FB docs walk thru how to login (handle asyc response from FB login) and show publish button, but what we need is to show "Post to FB" button, when the user clicks, i would like the user to login and then go to the preview of what is going to be posted and then post to FB.
I am using FB SDK and iOS 5, the difficulty is how to wire FB login flow directly to Post flow.
Thanks
Elango
Below is some code that I wrote that does this. If the user has not signed in to Facebook from the device settings, it is a better user experience to just call openActiveSessionWithPublishPermissions:, which does both the read and publish permissions in one step. Otherwise, you just do the two permissions serially. As soon as the read permission succeeds, you do the publish permission.
I tested this code on an iOS6 and iOS5 device, using Facebook SDK 3.2.1
- (BOOL)hasFacebookInDeviceSettings
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:#"com.apple.facebook"];
BOOL hasFacebookBuiltinAccount = (accountTypeFB != nil);
return hasFacebookBuiltinAccount;
}
- (BOOL)hasLoggedInToFacebookInDeviceSettings
{
if (![self hasFacebookInDeviceSettings]) {
return NO;
}
BOOL result = [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook];
return result;
}
- (void)openFacebookSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
if (![self hasLoggedInToFacebookInDeviceSettings]) {
// Simpler if we don't have the built in account
[FBSession openActiveSessionWithPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self facebookSessionStateChanged:session
state:state
error:error];
}];
}
else if (!FBSession.activeSession.isOpen) {
__block BOOL recursion = NO;
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (recursion) {
return;
}
recursion = YES;
if (error || !FBSession.activeSession.isOpen) {
[self facebookSessionStateChanged:session
state:state
error:error];
}
else {
assert(FBSession.activeSession.isOpen);
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound) {
[FBSession.activeSession requestNewPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,
NSError *error) {
[self facebookSessionStateChanged:session
state:FBSession.activeSession.state
error:error];
}];
}
}
}];
}
}
hasFacebookInDeviceSettings tells you if this device even supports Facebook from the settings (i.e. this is iOS6+).
hasLoggedInToFacebookInDeviceSettings tells you if the user has signed into to Facebook from the iOS6 Facebook device settings.
You'll need to create your own facebookSessionStateChanged: and other code, as described in the login tutorial