iPhone:- Wants to autoLogin through saved credentials in Facebook - iphone

In my app i have to login inside Facebook without using login page and directly move onto home screen of Facebook.
i have searched a lot but i didn't get anything.......
#interface Facebook (MyApp)
- (void)myAuthorize:(id<FBSessionDelegate>)delegate;
#end
#implementation Facebook (MyApp)
- (void)myAuthorize:(id<FBSessionDelegate>)delegate {
_permissions = [[NSArray arrayWithObjects:#"email", *(whatever you need)*, nil] retain];
_sessionDelegate = delegate;
[self authorizeWithFBAppAuth:NO safariAuth:NO]; // force in app auth
}
#end
Facebook *facebook = [[Facebook alloc] initWithAppId:MY_APP_FB_ID];
[facebook myAuthorize:self];

As far as I know, this is not possible. Because if you do this you will get the password for all the users and you can hack their account. So, FB does not allow this.

Related

Logout of Facebook in app using Facebook ios SDK

I have integrated Facebook login in my app and therfore user can login with both my app account and also Facebook and do corresponding actions.For Facebook integration I have added Facebook SDK.Now when Logout button is clicked in my app it has to clear all the credentials of Facebook Account.I have gone for :
-(IBAction)btnlogOutClicked:(id)sender
{
[appDelegate fbDidlogout];
}
-(void)fbDidlogout
{
FBSession* session = [FBSession activeSession];
[session closeAndClearTokenInformation];
[session close];
[FBSession setActiveSession:nil];
}
But when I again click on button I m redirected directly to my account without going to Facebook Login page.
How can I logout of Facebook?
Using new Facebook SDK login kit just write below line and thats it..
[[FBSDKLoginManager new] logOut];
If using swift, make sure to have the necessary imports
import FBSDKLoginKit
func logout() {
FBSDKLoginManager().logOut()
}
For logout you should try this
you can add the Logout button on Navigation Controller (Top Right Corner) in viewDidLoad method
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:#"Logout"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(logoutButtonWasPressed:)];
and the action method for above added button is
-(void)logoutButtonWasPressed:(id)sender {
[FBSession.activeSession closeAndClearTokenInformation];
}
Hope this will help you!
Reference
Edit:
As you asked why its not asking for UserName and Password,So the reason is :
When we integrate Facebook SDK in our app and try to login, it automatically check two places (to make sure we have already logged-in Facebook or not)
First of all It checks whether we have already logged-in into Facebook Native app which is installed on this device.
then It checks whether we have saved our FaceBook UserName and Password in Device Settings.
If both places we haven't logged-in then It will ask UserName and Password in application
you can check Facebook account setup in Device Settings as shown in below screen shot,
Press Home Button --> Settings -->Facebook
FBSDK is doing logout like this:
[FBSession.activeSession closeAndClearTokenInformation];
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
If using swift 3 or 4:
var loginManager = LoginManager()
Paste this code when some action is need to be done for logging out
loginManager.logOut()
In your postButtonClicked write following if else :
-(void)postButtonClicked
{
_session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
[_session resume];
posting = YES;
showSlideShow = 1;
if (_facebookName != nil)
{
[self logoutButtonClicked];
}
if (![_session isConnected])
{
self.loginDialog = nil;
_loginDialog = [[FBLoginDialog alloc] init];
[_loginDialog show];
}
else {
self.loginDialog = nil;
_loginDialog = [[FBLoginDialog alloc] init];
[_loginDialog show];
}
}

Redirect Back from uiweb view in gdata integration

I am making an application to integrate gmail to my app. I am able to login to gmail by gadata-objective c-client-1.11.0.a. I am giving the code
-(IBAction)googlelogin
{
NSString *scope = #"https://www.googleapis.com/auth/plus.me"; // scope for Google+ API
GTMOAuth2ViewControllerTouch *viewController = [[[GTMOAuth2ViewControllerTouch alloc] initWithScope:scope clientID:kMyClientID clientSecret:kMyClientSecret keychainItemName:nil delegate:self finishedSelector:#selector(viewController:finishedWithAuth:error:)] autorelease];
NSString *html = #"<html><body><div align=center>Loading sign-in page...</div></body></html>";
[viewController setInitialHTMLString:html];
[self presentModalViewController:viewController animated:NO];
}
now i want to redirect back to my app after google login to get the contacts of gmail. Help me how to generate taken and return back to my app after login
thanks
you should implement the method
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error != nil) {
// Authentication failed
} else {
// Authentication succeeded
// here you should push your the root view controller of your app.
}
}

No interaction with Facebook iOS SDK dialog after switching to thread?

I'm playing around a little bit with the Facebook iOS SDK.
I have a TabBar App (with MainWindow.xib) and I successfully integrated the Facebook SDK.
The problem is that non of the Facebook pop up dialogs are responding to my user interactions.
For example. I want to post something in the wall. The Facebook SDK opens a dialog but if i try to interacte with the dialog it doesn't happen anything.
The log tells me: [Switching to process 2365 thread 0x12d07]
How can I fix it?
I'm using the simulator.
The important code int the AppDelegate looks like that, it's actually more or less the same like on developer.facebook.com:
Thank you a lot.
// AppDelegate.h
#interface AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate, FBDialogDelegate> {
Facebook *facebook;
}
#property (nonatomic, retain) Facebook *facebook;
#property (strong, nonatomic) IBOutlet UIWindow *window;
#property (strong, nonatomic) IBOutlet UITabBarController *tabBarController;
// AppDelegate.m
#implementation AppDelegate
#synthesize facebook;
#synthesize window = _window;
#synthesize tabBarController = _tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
facebook = [[Facebook alloc] initWithAppId:#"APP_ID" andDelegate:self];
if (![facebook isSessionValid]) {
[facebook authorize:nil];
}
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
#end
Kind regards.
You need a method that posts to a feed, like the one below
-(void)postToFeed
{
MyAppAppDelegate *sharedAppDelegate = (MyAppAppDelegate *)[[UIApplication sharedApplication] delegate];
[sharedAppDelegate.facebook dialog:#"feed" andParams:params andDelegate:self];
}
I just hit this same problem. The problem for me was that my UIApplication keyWindow had userInteractionEnabled = NO. So not having that extra UIWindow present fixed it for me (more below).
I found this code in FBDialog.m
- (void)showWebView {
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) {
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
_modalBackgroundView.frame = window.frame;
[_modalBackgroundView addSubview:self];
[window addSubview:_modalBackgroundView];
....
so it's going to add the dialog to the keyWindow. I only had one window, so I thought. It turns out SVProgressHUD will create a new window with user interaction disabled and make it the key window (makes sense).
I'm guessing other HUD style things do this to. I was only showing the HUD while some prep work was done, so by the time I can show the dialog, I can remove it anyway. So that was my fix.
I dug this up by calling
NSLog(#"%#", [[UIApplication sharedApplication] windows]);
NSLog(#"%#", [UIApplication sharedApplication].keyWindow);
right before I was about to show the dialog and noticed
I had two UIWindow's
the key one's userInteractionEnabled was set to NO
Hope that helps.

fbDidLogin not called - iOS

I'm trying to implement facebook to my iOS app for a school project however I ran into a bit of a snag, namely the fbDidLogin method is not called.
I have created a sample object called FBFetcher as so:
#interface FBFetcher : NSObject <FBDialogDelegate,FBSessionDelegate,FBRequestDelegate> {
Facebook *facebook;
FBFetcher *facebookFetcher;
}
-(void)login;
#property (retain) Facebook *facebook;
#property (retain) FBFetcher *facebookFetcher;
#end
In the FBFetcher.m:
#implementation FBFetcher
#synthesize facebookFetcher,facebook;
-(void)login{
facebook = [[Facebook alloc] initWithAppId:#"...."];
NSArray *permissions = [[NSArray arrayWithObjects: #"offline_access",#"user_about_me", nil] retain];
[facebook authorize:permissions delegate:self];
}
-(void)fbDidLogin {
NSLog(#"Erfolgreich eingeloggt....");
}
#end
In my app delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[[controller facebookFetcher] facebook] handleOpenURL:url];
}
I have a separate view controller with n action tied to a UIButton:
facebookFetcher = [[FBFetcher alloc] init];
[facebookFetcher login];
I can access the login and authorization page, however the method fbDidLogin never gets called. Any suggestions?
The method never gets called because when you authorize, you are doing it in Safari. To take care of this, which I think is a bug from Facebook SDK by the way, open the facebook.m file and find the following line:
[self authorizeWithFBAppAuth:YES safariAuth:YES];
and change it to
[self authorizeWithFBAppAuth:NO safariAuth:NO];
This way you will never be sent to Safari, but everything will be done in a dialog.
Just test it and you'll see that the fbDidLogin method will get called.
Hope it will help
What about
- (void)fbDidNotLogin:(BOOL)cancelled
Does that get called?
Look for this function in Facebook.m. This is where Facebook calls your fbDidLogin function. First make sure this is being called, then debug into it. Make sure you've spelled/defined fbDidLogin correctly in your session delegate (no parameters). If not the respondsToSelector will fail and never call your delegate's function.
- (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate
{
self.accessToken = token;
self.expirationDate = expirationDate;
if ([self.sessionDelegate respondsToSelector:#selector(fbDidLogin)])
{
[_sessionDelegate fbDidLogin];
}
}

Facebook iOS - handleOpenURL & Tabbar Application

I'm having difficulties getting the Facebook Log In to kick back to the right view in my app and call the appropriate facebook functions.
In the example Facebook has simply [controller facebook] that is the view they start with. I am using a tabbar application though so I don't have the necessary reference. I made a pointer to the desired view and used it... it opened correctly but would not call any of the methods associated with facebook, specifically:
(void)fbDidLogin;
(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[*NotReferencedViewController* facebook] handleOpenURL:url];
}
Has anyone else run into this?
Not sure what example you're talking about, but you should create and store your Facebook object in a central place such as your Model or UIApplicationDelegate. Then it would be accessible through singletons so you always have access to it, for example:
[[UIApplication sharedApplication] delegate].facebook
So you can then access the facebook object from whatever view controllers need it.
When you do something like
NSArray* permissions = [[NSArray arrayWithObjects:#"email", #"read_stream", #"publish_stream", nil] retain];
[facebook authorize:permissions delegate:self];
specifying delegate:self means you will implement methods in that class that Facebook can call to inform you of certain events. One of those methods is fbDidLogin, and in there you can do whatever you need to:
-(void)authorizeFacebook {
NSArray* permissions = [NSArray arrayWithObjects:#"email", #"read_stream", #"publish_stream", nil];
[facebook authorize:permissions delegate:self];
}
// if the authorization succeeds it will come back to your app and call the method below
-(void)fbDidLogin {
// switch view, call the facebook graph, or do whatever else you like
}
You could do this in the app delegate itself, or in a view controller.
You can see the facebook delegate methods by inspecting the .h files of the facebook SDK: Facebook.h, FacebookRequest.h, etc.
Edit
And your handleOpenURL: method should look exactly as it does in fb's example (assuming you are not handling other url schemes):
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
http://developers.facebook.com/docs/guides/mobile/#ios