Facebook login via IOS app redirects to blank page - iphone

I previously had my IOS app integrated with the Facebook Graph API using the IOS SDK. I recently recreated the app on Facebook and now when it tries to authorize using:
[facebook authorize:permissions delegate:self];
My app gets redirected to a blank Facebook page with a cancel button at the top and then I get a callback to the fbDidNotLogin() method in my IOS app.
What's wrong?
I tracked it down to line 315 of Facebook.m:
if (!accessToken) {
It then eventually calls fbDialogNotLogin:NO. The errorCode and errorReason don't appear to be helpful.

Most likely your access token is expired or you removed the app from your facebook. You can log what error is returning to you from facebook to find out. In any case if you get to fbDidNotLogin implementation you need to remove access token details from NSUserDefaults (if you store it there) and reauthorize.
hope this helps

Related

How to Open Facebook API to open Login Dialog?

I m using facebook api from https://developers.facebook.com/docs/mobile/ios/
and using [facebook authorize:nil]; to open login dialog. But when I run on simulator it opens facebook dialog for login but when I run it in iphone It opens my facebook Application to login instead of facebook Dialog. I want to show facebook dialog when user is not login otherwise run code that I have applied.
If you logged in the Facebook account once from the simulator it goes to the desired feature next time onwards. Please check it.Thanks.
Facebook has an Single Sign On technique for permission grant. The tutorial that you are following does the same for you. It will open the Facebook App for you or the Safari, if it is not found. So the authentication process may remain clear under the oAuth protocol.

How to get Facebook access token and User ID on iphone

I want to make a demo of using OAuth to get a facebook access token in a mobile app.
i have a button on the main view. After button is clicked, I use safari to open the facebook OAuth dialog. After logging in to facebook, I can't figure out how to get the access token and UserID.
You need to spend some time reading the documentation on how Facebook works with iOS. Specifically there is a whole documentation section dedication to iOS authentication.
The way you are currently doing it with redirecting to Safari is not the preferred way of handling this as far as I know.

How to hide the facebook authorization dialog on iPhone?

I'm implementing facebook connect for my iPhone app. The current facebook SDK would keep you logged in unless you log out explicitly, which is fine with me as stay logged in is actually the requirement. However, I don't want the users to go press the log in button if they never logged out. In this case, I won't be able to grab the facebook object, which I'll need in other parts of my app. So I was planning to simulate the log in event anyways, but that led me to another problem: even though permissions are granted to my facebook app before, it will still pop up the authorization dialog to my users saying they have granted permissions to my app. My question is, how do I hide this? Or, is there a way that I can grab the valid facebook object without calling authorize on my facebook object when my app is restarted and the user stayed logged in?
Any suggestion would be appreciated.
You could redirect the user to https://www.facebook.com/login.php?api_key=<YOUR_APP_ID>. (This is the URL that the PHP Facebook SDK returns when you call getLoginUrl()).This will avoid the dialog and still allow users to authorize your app.

Facebook SDK iOS Login

Using the Facebook SDK for iOS, how does one figure out whether or not a user is already signed in so the app does not have to go through a login process?
Currently during the login process, I am saving the access token and expiration date to the user defaults and then reading those back out when I initialize a facebook object at the start of my application's run time.
But what happens if a user backgrounds the app, goes into Safari, changes to a different Facebook account or signs, then comes back into my own app. Shouldn't the Facebook app return that the stored session isn't valid anymore? How would I figure this out? Currently, my facebook object maintains that the session is valid, but unfortunately when I try to publish something, I see nothing on the appropriate Facebook page.
Am I missing something here? Thanks for your help!
You are doing the correct thing saving and restoring the facebook access token & expiration date. Any FB API that requires a valid token will fail with an error if you call it with an expired token. Handle the error and logout locally from FB then ask your user to login again.
In regards to Facebook's login on an iPhone (SDK v3.0+), it ranks the System Level Login 1st, Facebook native iOS app 2nd, and mobile Safari Facebook login 3rd. But if the user logged into your app using mobile safari, backgrounded the app, logged into a different Facebook account using mobile safari, then returned to your app, the access token and session in your app will be valid until you log out of your iOS app. Typically you log out using this line:
[FBSession.activeSession closeAndClearTokenInformation];
Login is initiated by some variation of this line:
[FBSession openActiveSessionWithReadPermissions:
If you're using Facebook iOS SDK 3.2+, you can call the following to see if an authenticated Facebook session is open:
[[FBSession activeSession] isOpen]
Also, you don't have to save the access token or expiration date locally. You can access them with these calls:
[FBSession activeSession].accessTokenData.accessToken
[FBSession activeSession].accessTokenData.expirationDate
Here's a link to some relevant Facebook iOS docs:
Facebook Login - iOS SDK

Problems with facebook connect

I am developing an application, which gives the user an option to share feeds using facebook connect. I am stuck at the start itself. I dowloaded the FBConnect sdk and implemented the code as explained in the documentation. Now when the fconnect button is touched in the application, instead of connect page opening, to grant the application permission, the facebook login page opens. Signing on to this page directs the user to facebook home. The facebook window never closes and the application doesn't get permission.
Please help me on this.
This behavior is caused by [FBSession session] not being a valid session.
I had this problem and it turned out to be because the session object had been deallocated. When you set the global session by calling [FBSession setSession:session] or if you initialize any FBSession object, FBSession doesn't retain it as it should, so make sure you retain the session object even if you don't actually use it or even keep a reference to it. If the session is there, make sure your api key and secret are correct.