Authlogic and iPhone app login - iphone

This has been a head-banger for me. I have looked at all of the similar questions on SO and none have proved satisfactory. Here's my go at it.
I have a perfectly fine rails 3 app setup with Authlogic.
I have been using Objective Resource (http://iphoneonrails.com/) to connect my iPhone app and my Rails app, and it has been working fine.
Now is the time to add authentication, and I cannot figure it out.
I have a UserSession class in my iPhone project with a username and password field. When the app launches, I present a login screen with username and password fields. Upon clicking a button, the iPhone app attempts to create the UserSession.
I took my code for doing that from http://www.corprew.org/blog/2010/01/27/authlogic-and-objectiveresource/
us.username = usernameField.text;
us.password = passwordField.text;
NSError * err = nil;
if(![us saveRemoteWithResponse:&err])
{
NSLog(#"%d", err);
NSLog(#"whoops, error");
}
When I run that code, the Log shows "0" and "whoops, error" meaning that the UserSession did not save. This occurs for both correct and incorrect logins.
Additionally, I have placed token comments in saveRemote ("I'm in saveRemote" etc.) and those never appear in my log.
Any ideas here?
If you want me to post anymore code, let me know. I will be up all night with this one.

Question resolved.
Don't use ObjectiveResource :-)
Switched to ASIHTTP and it's working fine for my needs right now.

Related

android facebook login button does not work

I'm following this tutorial "Facebook Login Flow for Android" (https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/) to create a simple app containing only one facebook login button to test facebook login.
However, I've been having trouble logging in facebook with this button.... I've been following every step in this tutorial and I've double checked everything -- it is exactly the same as in this tutorial. I see other people who have similar problems are always because of incorrect debug hash code. But I've checked like a million times that I got the correct debug hash code. Some people say that if you wanna release an app, you need a release code. However, I'm not releasing my app -- I'm just testing it on an android device, so I guess I dont really need a release code to do that?
Also, I've checked that I've included my facebook application id for this app in the Android Manifest. So basically, everything I did was strictly following the tutorials on Facebook Developers.
I've seen some people suggesting to use the "keytool" in JDK 6 in stead of JDK 7. And I've checked that I actually did generate my debug hash code with the "keytool" in JDK 6.
So I've tried everything, but the problem still exists!
In that Android Tutorial, it suggests putting this in your code so that you can monitor your LogCat to see if your current state is logged in or logged out:
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
In my case, no matter how many times I clicked Facebook Login Button, I always got "Logged out..." in my LogCat.
Also, the funny thing is, I can't even log in facebook using those sample apps coming with Facebook Android SDK 3.0.1 (eg. SessonLoginSample)!!!!! When I click the login button in those sample apps, nothing happens -- which means I'm not successfully logged in.
I really hope you guys out there can help me with this problem. It's weird I don't see other people with the exact same problem (as I said, those with similar problems are always because of incorrect debug code, but I've checked mine, it is 100% correct). THANK YOU SO MUCH!
It happened to me once. You might have added the export key hash in facebook developer setting.
Add these lines to your code to get your debugging key hash and then add to facebook.
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}

AS3 FacebookDesktop Login fail with OAuthException - #2500 An active access token must be used to query information about the current user

I think this is because Facebook just made some changes to their login process.
A few days ago, my air app was working with the FacebookDesktop class from the facebook-actionscript-api. Today I opened the project, and noticed that the Facebook login screens are a little different than when I started building my app. After I type my userID and password in, I grant the app access to my public profile, friend list and photos. Then another screen comes up where I grant the app permission to post to my friends on my behalf.
Then the window closes, and I get 'OAuthException 2500 An active access token must be used to query information about the current user.'
When I sign into Facebook through a browser, I see that my app shows up under "Your Apps" but I can't log in and do anything through my app.
I'm using Adobe Flash with GraphAPI_Desktop_1_8_1.swc on OSX Lion.
Here is my code:
public function MyApp(){
FacebookDesktop.init(APP_ID, onInit);
}
protected function onInit(result:Object, fail:Object):void {
if (result) {
trace("onInit, Logged In\n");
} else {
trace("onInit, Not Logged In\n");
var permissions:Array = ["publish_stream", "user_photos"];
FacebookDesktop.login(onLogin, permissions);
}
}
protected function onLogin(result:Object, fail:Object):void {
if (result) {
trace("Logged In as:");
trace(FacebookDesktop.getSession().user.name);
} else {
trace("Login Failed");
trace('code: '+fail.error.code); //code: 2500
trace('message: '+fail.error.message); //message: An active access token must be used to query information about the current user.
trace('type: '+fail.error.type); //type: OAuthException
}
}
I get the same results when I use the FlashDesktopExample provided in the SDK (modified with my app ID of course).
Any help would be great! Thanks in advance!
I ran into this problem, too: the success URL did not have any parameters.
Cadderly82 is correct; it's a problem with secure navigation. Turning off my Facebook account's "Secure Browsing" option fixed the problem, but I didn't want to have to require users to do that.
I was able to solve this by setting ALL of the FacebookURLDefaults values to use "https://".
Now I get a valid user-access-token in the success URL; and I get valid values regardless of my facebook account's secure-browsing setting.
I have figured out the problem:
The LoginWindow class sets the token based on the uri.
This worked fine until the LOGIN_SUCCESS_URL (http://www.facebook.com/connect/login_success.html) and the LOGIN_SUCCESS_SECUREURL (https://www.facebook.com/connect/login_success.html) pages stopped including the access token in the uri.
Hence, the token is never set. Even though my app shows up under the 'Your Apps' section in Facebook after I login, my app still can't do anything without a token.
I have two solutions:
The easiest is to change the LOGIN_SUCCESS_URL and/or the LOGIN_SUCCESS_SECUREURL properties in com.facebook.graph.core.FacebookURLDefaults like the following.
beginning on line 82:
public static var LOGIN_SUCCESS_URL:String = 'http://www.facebook.com/connect/login_success.html';
public static var LOGIN_SUCCESS_SECUREURL:String = 'https://www.facebook.com/connect/login_success.html';
Change to:
public static var LOGIN_SUCCESS_URL:String = 'http://www.yourwebsite.com/';
public static var LOGIN_SUCCESS_SECUREURL:String = 'https://www.yoursecurewebsite.com/';
of course you would use your own website - not 'http://www.yourwebsite.com/'. I tried it using http://localhost/ and it worked great.
Another solution is:
Change com.facebook.graph.windows.LoginWindow with the following code. I have made some changes to my files, so please forgive me if the line numbers are different than what they are in a fresh copy of the SDK.
around line 143:
change:
vars.redirect_uri = FacebookURLDefaults.LOGIN_SUCCESS_URL;
to:
vars.redirect_uri = 'http://localhost/';
In production code, you probably want to use your own website address instead of localhost, but I used localhost for testing purposes.
Then, in the handleLocationChange function (should be around line 168) add this to the else if statements:
}else if (html.location.indexOf ('http://localhost/') == 0) {
loginCallback(getURLVariables(), null);
userClosedWindow = false;
html.stage.nativeWindow.close();
html.removeEventListener(Event.LOCATION_CHANGE, handleLocationChange);
}
As I said before, change localhost to your website address.
I hope this helps!
I was having the same problem for random users and I don't really know if it is a Facebook problem with secure navigation:
Check user properties in Facebook: Security Settings > Secure Browsing
(www.facebook.com/settings?tab=security)
For users with "disabled" state it works fine.
For users with "migration" state it gives the error.
For users with previously "enabled" state it works fine.
When I tried with users in "migration" state and changed to "disabled", it worked fine.
Then if I turned it "enabled", the "migration" state is gone and marked as "enabled", but the error it's still there.
So I guess this is the problem, but don't know how to fix it.
alot has change in a year this is what i think the answer is now
you need a token to login FacebookDesktop.getSession().accessToken
public function MyApp(){FacebookDesktop.init(APP_ID, onInit, FacebookDesktop.getSession().accessToken); }

Heroku - Application Error, but no error in logs

I'm hacking away at a Facebook app on Heroku, using Node.js. When I go to the app myself, it works exactly as I expect. When I send another developer/tester to it, the standard Heroku "Application Error" message is displayed. When I check the logs, there isn't even a log that the developer made a GET request for the app page, let alone an error.
He tells me that the last thing he sees in his browser status bar is "waiting for .herokuapp.com", which implies that Facebook got to the app, but the logs don't support this theory.
Is there another method of seeing Heroku errors? Is there something I have to turn on in order to see more? A setting I have to modify to let this other guy use the app?
Update: Some more looking around led me to check the network traffic. He's getting a 503 Service Unavailable, followed by the error page. Still wondering why this happens on his machine, but not mine.
Update: Inserted some error-checking code into the handle_facebook_request method.
req.facebook.app(function(err, app) {
if(err !== null) {
var errorMessage = "Error getting app: " + util.inspect(err['error']);
console.log(errorMessage);
}
// rest of req.facebook.me, and rendering code
}
This gives me an "Unsupported get request", of type "GraphMethodException" and code 100. So now I have something I can look into! I wish that Heroku had at least mentioned that the request had been tried.
I had the same problem with a new facebook app created with the support heroku / node.js.
After several attempts and tests I saw that I get the message "Unsupported get request", type "GraphMethodException" and the code 100, because my facebook app was with sandbox mode.
When I disabled the sandbox my application on heroku it worked fine.

iOS 6 - Facebook sharing procedure fails with error "The proxied app is not already installed"

Though, there is such a question Facebook Error (7) iOS 6 it's already closed without any answer!
While obtaining an access to user's facebook account I've got an error:
error is: Error Domain=com.apple.accounts Code=7 "The Facebook server could not fulfill this access request: The proxied app is not already installed." UserInfo=0xa260270 {NSLocalizedDescription=The Facebook server could not fulfill this access request: The proxied app is not already installed.}
I'm performing a request like this:
self.statusLabel.text = #"Waiting for authorization...";
if (self.accountStore == nil) {
self.accountStore = [[ACAccountStore alloc] init];
}
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary * dict = #{ACFacebookAppIdKey : FB_APP_ID, ACFacebookAudienceKey : ACFacebookAudienceEveryone};
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
__block NSString * statusText = nil;
if (granted) {
statusText = #"Logged in";
NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
self.facebookAccount = [accounts lastObject];
NSLog(#"account is: %#", self.facebookAccount);
self.statusLabel.text = statusText;
[self postToFeed];
}
else {
self.statusLabel.text = #"Login failed";
NSLog(#"error is: %#", error);
}
}];
What does this error means?
I've solved this problem!
It was because I do not pass permissions array!
Though the ACAccountStore class states that this parameter is optional, it is not!
More over the application could launch and ask for basic permissions(as it is implied)!
So, you must always pass a permissions array.
Here's also a description of error codes returned by account store:
typedef enum ACErrorCode {
ACErrorUnknown = 1,
ACErrorAccountMissingRequiredProperty,
ACErrorAccountAuthenticationFailed,
ACErrorAccountTypeInvalid,
ACErrorAccountAlreadyExists,
ACErrorAccountNotFound,
ACErrorPermissionDenied,
ACErrorAccessInfoInvalid
} ACErrorCode;
(I've got ACErrorPermissionDenied here)
We had the same problem and after taking a closer look at the iOS facebook documentation ad
https://developers.facebook.com/docs/howtos/ios-6/
I noticed the following paragraph:
Note, to use iOS 6 native auth, apps need change the way they request permissions from users - apps must separate their requests for read and write permissions.
I must have read over that one several time but it contained the solution:
You have to do multiple request for access if you want to grant write (publish access). So now we first ask for permission 'email' to get read permission and then for 'publish_action' to be able to post to the timeline.
The error message is not clear since "app" could be your iOS app? Facebook.app on the phone? Facebook app? The "proxied app" is the Facebook app, and "not already installed" means, it's not yet been associated with the Facebook user online in terms of permissions.
The first time your Facebook app connects to the users Facebook account, you must specify the basic info value(s) in your ACFacebookPermissionsKey key of the options dictionary. Other Facebook SDK's past and present such as the Javascript or PHP libraries by default supply basic info as the key, so you never had to. It seems the native integration in iOS doesn't do this, thus, if when the user first connects your app to their Facebook account with no permissions supplied, you get this error.
After you are given access, i.e. - after the user is connected to the app in their privacy settings online, ACFacebookPermissionsKey does as Apple document, become optional.
It's all a little confusing when you start to try and use the native Facebook integration...
Using the native Facebook integration you must provide one of the following keys which are basic info keys: email, user_birthday, or user_location.
To quote Facebook (source):
To create this basic connection using the iOS 6 native Auth Dialog,
apps must request access to a user's basic profile information by
asking for one of email, user_birthday, or user_location permissions.
After experiencing this error on one of my devices (after seeing the correct, expected iOS alert view asking for me to approve Facebook access to my app):
'The Facebook server could not fulfill this access request: Invalid application ID.'
I finally found the problem.
Although it initially appears to be a problem with the Facebook app setup on the FB developer site it turned out that my device's iOS Facebook account no longer had a valid password associated with it - this can happy when users restore an iOS backup to a new device. Once I sorted that in my device settings everything worked as expected.
I've not experienced any problems requesting 'publish_stream' in the first FB permissions access request - I actually think the real problem here is that the error messages are so random that they don't help developers to locate the source of the errors we're experiencing thanks to Apple and Facebook's lack of unity!
A few more things that one can try other than the above suggestions is checking your app settings on facebook.com here -
https://developers.facebook.com/apps/<*APP_ID*>/summary
Make sure that the SandBox Mode is set to Off
Also,
Under "Select how your app integrates with Facebook"
Select-> Native iOS App
Set your Bundle ID
You can set any temporary integer value for iPhone/iPad App store ID
Set Facebook login to Enabled
Listed Platforms is Native iPhone App &/or Native iPad App
Save changes and try after some time as it might take a few minutes for facebook to sync the changes to all its servers.

iphone facebook session failing. why?

I'm learning how to integrate facebook api in iphone app.
First I visited facebook website, went to applications->developer and created an app. Noted down private key and secret key.
Now, I'm using FBConnect sample code. I am using my keys in FBConnect app. And I set session proxy as
static NSString* kGetSessionProxy = #"SessionViewController"; // #"<YOUR SESSION CALLBACK)>";
I'm able to run the app and when I click "Connect to Facebook", its asking me for credentials as well. But afte providing credentials, its failing. The following delegate method is being called:
- (void)sessionDidNotLogin:(FBSession*)session { _label.text = #"Canceled login"; }
I'm not understanding why I'm ending up in above delegate.
What are all options that I've to select in facebook website when creating new application?
Please help me.
When I made kGetSessionProxy to nil, it worked without any problem. But I didn't understand why it didn't when i gave some value.