2013-10-21 53 views
0

我是新手,我使用下面的代碼進行手機編程,我正在從Facebook獲取信息。 但問題是,如果點擊按鈕,它會去Facebook應用程序問Facebook的用戶名和密碼後,它顯示相同的view.But在這裏我提取用戶信息,但IAM無法獲取information.Its後開放Facebook頁面回到相同的頁面。再次點擊也重複同樣的事情。可以任何一個告訴如何解決這個問題。我無法在ios中獲取Facebook用戶信息

FBLoginView *fbLoginview = [[FBLoginView alloc] initWithPermissions:[NSArray arrayWithObject:@"publish_actions"]]; 

    //loginview.frame = CGRectOffset(loginview.frame, 2, 2); 
    // loginview.frame = loginWithFbButton.frame; 

    fbLoginview.frame = CGRectMake(30, 10, 200, 30); 
    for (id obj in fbLoginview.subviews) 
    { 
     if ([obj isKindOfClass:[UIButton class]]) 
     { 
      loginWithFbButton = obj; 
      loginWithFbButton.frame = CGRectMake(0, 0, 200, 30); 

      // UIImage *loginImage = [UIImage imageNamed:@"YourImg.png"]; 
      [loginWithFbButton setBackgroundColor:[UIColor colorWithRed:69.0/255.0 green:115.0/255.0 blue:185.0/255.0 alpha:1]]; 
      [loginWithFbButton setBackgroundImage:nil forState:UIControlStateNormal]; 
      [loginWithFbButton setBackgroundImage:nil forState:UIControlStateSelected]; 
      [loginWithFbButton setBackgroundImage:nil forState:UIControlStateHighlighted]; 

      // [loginWithFbButton addTarget:self action:@selector(LoginWithFacebookk:) forControlEvents:UIControlEventTouchUpInside]; 
      [loginWithFbButton.layer setBorderWidth:1.0f]; 
      [loginWithFbButton.layer setBorderColor:[UIColor colorWithRed:225.0/255.0 green:227.0/255.0 blue:231.0/255.0 alpha:0.6].CGColor]; 
      // [loginWithFbButton sizeToFit]; 

      loginWithFbButton.layer.masksToBounds = YES; 
      loginWithFbButton.layer.cornerRadius = 5; 

      [loginWithFbButton setTitle:@"   Get info from Facebook" forState:UIControlStateNormal]; 
      [loginWithFbButton.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:13]]; 
      loginWithFbButton.titleLabel.textAlignment = NSTextAlignmentCenter; 
      loginWithFbButton.titleLabel.backgroundColor = [UIColor clearColor]; 
      loginWithFbButton.titleLabel.textColor = [UIColor whiteColor]; 


      CAGradientLayer *gradient1 = [CAGradientLayer layer]; 
      gradient1.frame = loginWithFbButton.bounds; 

      UIColor *startColour1 = [UIColor colorWithRed:46.0/255.0 green:174.0/255.0 blue:225.0/255.0 alpha:1.0f]; 
      UIColor *endColour1 = [UIColor colorWithRed:46.0/255.0 green:119.0/255.0 blue:225.0/255.0 alpha:1.0f]; 

      gradient1.colors = [NSArray arrayWithObjects:(id)[startColour1 CGColor], (id)[endColour1 CGColor], nil]; 
      [loginWithFbButton.layer insertSublayer:gradient1 atIndex:0]; 


      [fbLoginview addSubview:loginWithFbButton]; 
     } 

     if ([obj isKindOfClass:[UILabel class]]) 
     { 
      UILabel * loginLabel = obj; 
      loginLabel.text = nil; 
      loginLabel.textAlignment = NSTextAlignmentCenter; 
      loginLabel.frame = CGRectMake(0, 0, 271, 26); 
     } 
    } 

    // fbLoginview.delegate = self; 

    [loginTempview3 addSubview:fbLoginview]; 
+2

Facebook的代碼在哪裏? –

回答

1

請確保您有實現Facebook的委託方法,

fbLoginview.delegate = self; 

而實現此方法獲取用戶信息

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView 
          user:(id<FBGraphUser>)user { 
    // here we use helper properties of FBGraphUser to dot-through to first_name and 
    // id properties of the json response from the server; alternatively we could use 


    NSLog(@"user :%@",user); 
} 
+0

感謝您提供重播我將盡力.. –

0

也許這不是你的問題!沒有人能夠在Facebook上發佈,評論或發表評論。這可能是原因...也許它在一個小時內運行良好!

相關問題