Facebook login on iPhone app - iphone

I am trying to allow users to login to my app, through Facebook. I am following this guide https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/
I have followed all of the steps including the step named "Getting started with the Facebook sdk for iOS".
When I copy and paste the following method, I get an error here:
return [FBSession openActiveSessionWithPermissions:permissions
Here is the method I copied and pasted.
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"user_likes",
#"read_stream",
nil];
return [FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
The error says this: "No known class method for selector 'openActiveSessionWithPermissions:allowLoginUI:completionHandler:'"
Can someone help me figure out what I am doing wrong?
Let me know if you'd like to see some more of my code to figure the problem out.

update you facebook sdk to the latest one, and follow Scrumptious example.

I really doubt this is gonna solve your problem, but it's worth a shot. NSError usually takes an ampersand ("&") before getting passed as an argument. So write it as error:&error instead.

Complementing mLamaa answer, take a look on Facebook Upgrade Guide and follow these 2 steps:
1- Update facebook SDK
2- Replace the openActiveSessionWithPermissions function to openActiveSessionWithReadPermissions
Reference:
https://developers.facebook.com/docs/ios/upgrading/
Upgrading from 3.0 to 3.1
"Therefore, if your app previously used v3.0 of the SDK, you will need to remove usage of openActiveSessionWithPermissions:allowLoginUI:completionHandler: and replace it with openActiveSessionWithReadPermissions:allowLoginUI:completionHandler: (or even more simply, openActiveSessionWithAllowLoginUI)."

Related

Facebook SDK FBSession infinite loop and crash

I originally used FBLoginView to start the login process in the latest Facebook SDK (3.5). However, that would crash the app because of a loop of some sort. I then read that I should try logging in using the code below as a test:
[FBSession openActiveSessionWithReadPermissions:[NSArray arrayWithObjects:#"read_stream", nil] allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// session might now be open.
NSLog(#"Error - %#", error);
}];
I got exactly the same issue. A huge number of processes (with the same name) get called and the app crashes. Does anyone know why this would happen when using the Facebook SDK? Here is an image of the thread that crashes:
As you can see there's something not right here. Anyone got any ideas?
Regards,
Mike
This was a bug and is now fixed.
Edited --
This has been fixed on both client and server as of the Facebook SDK 3.5.1 for iOS. Here is the link:
https://developers.facebook.com/resources/facebook-ios-sdk-3.5.1.pkg
--
Thanks for notifying us of this problem!
I had the same issue, and tried setting sandboxing (in fb app dashboard) to false, and then it worked...
I'm having what seems to be the exact same problem, and nearly the same stacktrace,but I already have sandboxing disable, in fact, my app has been in production for 9 months, but we were using still sdk 2.0 and just gotten around to upgrade it.
I have narrowed It down a lot. Here I give a good explanation about my problem, and a temporary solution that fixes my problem, but It's viable for production..
Facebook SDK FBLoginView getting EXC_BAD_ACCESS

Facebook iOS SDK 3.1 openActiveSession.. always returns 0

I am working on an application that needs to be able to upload an image for the app for iOS versions 5.0+. For iOS 6, I have easily implemented the social feed that works perfectly.
For iOS 5, I am using the Facebook iOS SDK version 3.1. I use the methods that were in the tutorials, and so when I got to publish the image on iOS <6.0, I call the following method:
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
return [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObjects:#"publish_actions", nil] defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self sessionStateChanged:session
state:status
error:error];
}];
}
With [self openSessionWithAllowLoginUI:YES]; I always get back NO (0) and sessionStateChanged:state:error is never called due to it returning 0.
I have the app set up correctly, the two different parts set up in the plist, etc. etc., but for some reason this code on my iOS 5.0 device does not want to return correctly. (Just like in openSessionWithAllowLoginUI almost always returns NO)
Does anyone have any solutions on why it would always be returning no? I have the official FB app installed on the device, I am logged into my account...I am not getting any errors or anything...
Thanks in advance!

Facebook IOS SDK 3.1 - reauthorizeWithPublishPermissions?

Just upgraded to the Facebook iOS SDK 3.1 and already running into problems.
My app can't find the facebook method reauthorizeWithPublishPermissions, and it also hasn't got a clue what the static FBSessionDefaultAudienceFriends definition is!
Anyone else seen these problems? Can't believe that the 3.1 SDK would have these basic bugs in it, so I'm blaming my stupidity for now!!
For completeness, here is my code:
[FBSession reauthorizeWithPublishPermissions:[NSArray arrayWithObjects:#"publish_stream", #"publish_actions",nil]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
// Do something...
}];
Thanks.
#Zotter, answer is depreciated. Now (with latest Facebook iOS SDK, I guess v.3.19) you've to use - (void)requestNewReadPermissions:(NSArray *)readPermissions completionHandler:(FBSessionRequestPermissionResultHandler)handler; method, to authorise app with publish permissions.
[FBSession.activeSession requestNewPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if(!error) {
}
}];
/*! No audience needed; this value is useful for cases where data will only be read from Facebook */
FBSessionDefaultAudienceNone = 0,
/*! Indicates that only the user is able to see posts made by the application */
FBSessionDefaultAudienceOnlyMe = 10,
/*! Indicates that the user's friends are able to see posts made by the application */
FBSessionDefaultAudienceFriends = 20,
/*! Indicates that all Facebook users are able to see posts made by the application */
FBSessionDefaultAudienceEveryone = 30,
reauthorizeWithPublishPermissions: is an instance method
[FBSession.activeSession reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:
^(FBSession *session,
NSError *error)
{
...
}];
I had this problem. I was using an old version of Cocoapods that wasn't properly upgrading the source from 3.0 to 3.1. If you're using Cocoapods, upgrade to 0.14.0 and try again. If not, double check to make sure you have the latest Facebook SDK from master - if you don't see those values in FBSession.h, you probably have an old version of the SDK.

post image on Facebook wall and facebook friends wall

I am very tired with the problems of API, like Facebook Graph API, weather API etc.
I've used both API in my project. Graph API for Facebook and Google weather API for weather, but now on time of project completion, both API are not working. Google weather API depreciated in November,
And the Facebook features I've been using (post image on wall and post image on friend wall) were working last day, but now they don't.
The problem is that when I log in, I get the message The page you requested is not Found and below a link to go back to the previous page.
And when i click the link "back to previous page" it shows message:
An error has occurred with AppName, please try again
API error code : 100
API error Description : Invalid Parameter
Error_message : cancel_URL URL is not properly formatted
I wants to know solution of Facebook API. Is this problem is with every developer? if API modified or changed what we can do regarding?
How long ago did you update your facebook API? About two weeks ago I had to remove my entire API, redownload, and change all the posting code my app was using. It stopped working entirely and had no idea until app users complained. Some necessary changes for the new facebook API:
Facebook recommends putting these in your appDelegate if you look at the newest sample apps.
#import <FacebookSDK/FacebookSDK.h>
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [NSArray arrayWithObjects:#"publish_actions", nil];
return [FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if(state==513){
//facebook usage has been approved
}
}];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// We need to handle URLs by passing them to FBSession in order for SSO authentication
// to work.
return [FBSession.activeSession handleOpenURL:url];
}
And whereever you want to make your post put something like this:
if(facebookEnabled==YES)
{
NSString *fbText=[NSString stringWithFormat:#"whatever text you want to post";
[FBRequestConnection startForPostStatusUpdate:fbText
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
}];
}
Let me know if you have questions. Hope it helps!
Well I'm not sure it's your code's fault but Facebook is having issues right now.
My FB app in iOS doesn't work anymore. You can try again by enabling sandbox mode (in FB app settings) with a developer account. It works for me.
http://developers.facebook.com/bugs/463219573709230?browse=search_504fc79a6ea272d92740759
look on my solution, but it's only for posting on user wall
http://www.developers-life.com/facebook-compose-view.html

Facebook SDK: openActiveSessionWithPermissions completionHandler not called

Using the code from Facebook I have implemented
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"publish_actions",
nil];
return [FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
NSLog(#"error %#", error);
[self sessionStateChanged:session
state:state
error:error];
}];
}
It returns NO which I understand because it's a first time login, and the loginUI works (it sends the user to FB and asks them to give permissions) and then returns but completionHandler block is never ever run. It just returns to the app and nada.
I assume you following Implement the Login Flow of Facebook SDK but worth reading that section again as it explains everything. Make sure that you handled openURL and handleOpenURL methods in delegate. Also check openSessionWithAllowLoginUI almost always returns NO
Little late, but just in case someone comes checking...
Switching from openActiveSession to the instance method openWithCompletionHandler did the trick for me.
from the official doc
handler
... If a block is provided, the FBSession object will call the block each time the session changes state.
I fixed this problem my solving Open Graph setups and by studying Scrumptious example code from FB such as these functions [FBSession.activeSession handleOpenURL:url] and [FBSession.activeSession handleDidBecomeActive];