应用程序需要登录通过Facebook account.If Facebook帐户没有在手机中配置它工作正常,并成功登录到应用程序,但当Facebook帐户被配置并尝试登录到应用程序时,它会给我一个错误
Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)" UserInfo=0x9dce820 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginDisallowedWithoutError, com.facebook.sdk:ErrorSessionKey=<FBSession: 0x9dab260, state: FBSessionStateClosedLoginFailed, loginHandler: 0x0, appID: 326324637530004, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xa9cc040>, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}请参阅我的源代码
AppDelegate.h
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) FBSession *session;
@end
AppDelegate.m
#import "AppDelegate.h"
#import <FacebookSDK/FacebookSDK.h>
@implementation AppDelegate
@synthesize session = _session;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBProfilePictureView class];
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [FBSession.activeSession handleOpenURL:url];
}
Login.h
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
@interface Login : UIViewController<FBLoginViewDelegate>
@property (strong, nonatomic) id<FBGraphUser> loggedInUser;
@end
Login.m
#import "Login.h"
#import <FacebookSDK/FacebookSDK.h>
@interface Login ()
{
FBLoginView *loginview;
}
@property (strong, nonatomic) IBOutlet UIButton *FB_login;
@end
@implementation Login
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
loginview = [[FBLoginView alloc] init];
loginview = [[FBLoginView alloc] initWithReadPermissions:[NSArray arrayWithObjects:@"email",@"public_profile",nil]];
loginview.frame =CGRectMake(10,100, 280, 55);
loginview.delegate = self;
[self.view addSubview:loginview];
}
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
NSLog(@"Logged In");
}
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
NSLog(@"User info ");
}
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView {
NSLog(@"Logged out");
[FBSession.activeSession closeAndClearTokenInformation];
}
- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error {
NSLog(@"FBLoginView encountered an error=%@", error);
}发布于 2014-11-19 05:03:26
请确保将您的权限初始设置为'email',“未事先安装代理应用程序无法请求发布权限。”
loginview.readPermissions = @[@"email"];此外,还要确保在developers.facebook.com中正确设置了生产应用程序
https://developers.facebook.com/docs/ios/getting-started/#prerequisites
https://stackoverflow.com/questions/24752442
复制相似问题