Facebook Dialog委托回调值

时间:2012-03-01 21:53:56

标签: iphone objective-c facebook facebook-graph-api

尝试在我的iphone App上实施Facebook iOS SDK。我使用FBDialog Delegate允许用户登录并使用委托获得响应/回调。

登录成功后,我想从用户那里获取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);
}

2 个答案:

答案 0 :(得分:1)

didReceiveResponse中,响应开始时调用的委托方法(尚未完成和解析)从响应对象中获取statusCode

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

答案 1 :(得分: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