2012-03-01 76 views
0

試圖在我的iphone應用上實現Facebook iOS SDK。我正在使用FBDialog委託來允許用戶登錄並使用委託獲取響應/回調。Facebook對話框代表回調值

我想在登錄成功後從用戶那裏獲取response_type中的代碼。 任何人都可以幫我在這裏或讓我知道從哪裏接受指導。

我有以下的代碼實現:

-(void) login{ 
self.fb = [[Facebook alloc] initWithAppId:AppID andDelegate:self]; 


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
if ([defaults objectForKey:@"FBAccessTokenKey"] 
    && [defaults objectForKey:@"FBExpirationDateKey"]) { 
    self.fb.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; 
    self.fb.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; 
} 

fb.sessionDelegate = self; 
NSMutableDictionary *params = [NSMutableDictionary dictionary]; 
[params setObject:AppID forKey:@"client_id"]; 
[params setObject:@"code" forKey:@"response_type"]; 

[fb dialog:@"oauth" andParams:params andDelegate:self]; 

NSLog(@"Callback: %@", params); 
} 

回答

0

只需辦理委託方法:

/** 
* Your application should implement this delegate to receive session callbacks. 
*/ 
@protocol FBSessionDelegate <NSObject> 

@optional 

/** 
* Called when the user successfully logged in. 
*/ 
- (void)fbDidLogin; 

/** 
* Called when the user dismissed the dialog without logging in. 
*/ 
- (void)fbDidNotLogin:(BOOL)cancelled; 

/** 
* Called when the user logged out. 
*/ 
- (void)fbDidLogout; 

@end 
+0

但我期待找回像這裏一樣代碼和錯誤來自Facebook的會議代表特定的返回數據:在返回數據段http://developers.facebook.com/docs/reference/dialogs/oauth/。我怎樣才能實現它? – Change 2012-03-02 16:53:24

1

didReceiveResponse,當響應開始叫委託方法(尚未完成,解析),從響應對象中獲取statusCode

- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response { 
    if (200 == [response statusCode]) { 
     NSLog(@"Success"); 
    }  
} 
+0

如果這個答案是正確的,你應該接受它。這就是Stack Overflow的工作原理。 – tooluser 2013-06-17 20:53:16