- (void)请求:(FBRequest *)请求didLoad:(id)结果未被调用

时间:2012-06-05 06:36:41

标签: facebook facebook-graph-api

为什么这个方法从未调用过?谁可以帮我查看我的代码,我是一个绿色的手。

这是我的* .h文件

@interface LoginViewController : UIViewController <FBSessionDelegate,FBRequestDelegate,FBDialogDelegate> {

    Facebook *facebook;
    IBOutlet UITextField *_txt;
    NSString *facebookUserID;

我想获得faceboo用户ID,所以我调用了API'[facebook requestWithGraphPath:@“me”andDelegate:self];'

- (void) fbDidLogin
{
    NSLog(@"[LOGIN] Used did login");
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    // User has logged in to Facebook, now get their userId from Facebook 
    [facebook requestWithGraphPath:@"me" andDelegate:self];     
}

我知道下面的方法将获取用户ID,但它从未调用过。

- (void)request:(FBRequest *)request didLoad:(id)result 
{
    NSLog(@"Inside didLoad");     
    if ([result isKindOfClass:[NSArray class]])
    {
        result = [result objectAtIndex:0];
    }
    // When we ask for user infor this will happen.
    if ([result isKindOfClass:[NSDictionary class]])
    {
        //NSDictionary *hash = result;         
        NSLog(@"Name: %@", [result objectForKey:@"name"]);

        self.facebookUserID = [result objectForKey:@"id"];
        NSLog(@"ID: %@", [result objectForKey:@"id"]);
    }
}

1 个答案:

答案 0 :(得分:0)

您需要实现openURL或handleOpenURL(后者优先于ios 4.2)。它需要在您的app委托中实现,而不是在您的视图控制器中实现。

fbDidLogin not called。 openURL将导致调用fbDidLogin

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    NSLog(@"============HANDLE OPEN URL");
    ViewController *v =(ViewController *) vc;
    return [[v facebook] handleOpenURL:url]; 
}