我无法在ios中获取facebook用户信息

时间:2013-10-21 13:16:05

标签: iphone ios facebook

我是使用以下代码进行手机编程的新手。我从Facebook获取信息。 但问题是,如果点击按钮,它将转到Facebook应用程序询问Facebook用户名和密码后,它显示相同的视图。但在这里我获取用户信息,但我无法获取信息。它返回后打开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];

3 个答案:

答案 0 :(得分:0)

用于获取用户信息使用Facebook图形API

请查看此https://developers.facebook.com/docs/ios/ios-sdk-tutorial/

答案 1 :(得分:0)

确保您已实施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);
}

答案 2 :(得分:0)

也许这不是你的问题!没有人能够发布或喜欢或评论Facebook ..这可能是原因......也许它在一个小时内再次运作良好!