我被Facebook API難住登錄了。我找不到任何有用的東西。Facebook OAuth api登錄問題
我FBSessionDelegate方法不會被調用,並和的accessToken EXPIRATIONDATE值沒有被設置,所以我不認爲我會永遠登錄。
我恢復了一個非常簡單的應用程序,只有兩個按鈕(登錄,註銷)和標籤以查看狀態信息。
下面是視圖控制器,其中所有的處理髮生的代碼:
//
#import <UIKit/UIKit.h>
#import "Facebook.h"
@interface facebook_login_testViewController : UIViewController <FBSessionDelegate>{
UIButton *loginButton;
UIButton *logoutButton;
UILabel *info;
Facebook *facebook;
}
@property (nonatomic, retain) Facebook *facebook;
- (void) loggingIn;
- (void) loggingOut;
@end
和
#import "facebook_login_testViewController.h"
@implementation facebook_login_testViewController
@synthesize facebook;
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[loginButton setTitle: @"Log In" forState:UIControlStateNormal];
[loginButton addTarget:self action:@selector(loggingIn) forControlEvents:UIControlEventTouchUpInside];
loginButton.frame = CGRectMake(200, 200, 200, 50);
logoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[logoutButton setTitle: @"Log Out" forState:UIControlStateNormal];
[logoutButton addTarget:self action:@selector(loggingOut) forControlEvents:UIControlEventTouchUpInside];
logoutButton.frame = CGRectMake(200, 300, 200, 50);
info = [[UILabel alloc] initWithFrame:CGRectMake(200, 400, 400, 600)];
info.numberOfLines = 0;
[self.view addSubview:loginButton];
[self.view addSubview:logoutButton];
[self.view addSubview:info];
info.text = @"Waiting to log in...\n\nPress the login button.";
facebook = [[Facebook alloc] initWithAppId:@"159...........5" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void) loggingIn{
if (![facebook isSessionValid]) {
[facebook authorize:nil];
}
}
- (void) loggingOut{
info.text = [NSString stringWithFormat:@"\naccess token: %@\nexpiration date: %@\nfacebood description:%@\n",facebook.accessToken, facebook.expirationDate, facebook];
[facebook logout:self];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
@end
的的.plist文件被設置爲這樣
這真的看起來太簡單了,錯了。當我點擊登錄按鈕時,我可以跟蹤authorize:permission
,然後authorize:permissions localAppId:localAppId
,並且就我可以追蹤它而言,我沒有看到任何看起來會導致isSessionValid
成爲TRUE的結果。
我等待,然後按註銷按鈕,看看Facebook的一些參數,在萬一發生異步的需要,他們仍然是零。
有人能看到我缺少的東西嗎?