0

我是使用以下代码进行电话编程的新手,我正在从 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];
4

3 回答 3

0

Make sure you have implement facebook delegate methods,

fbLoginview.delegate = self;

And implement this method to get user information

- (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);
}
于 2013-10-21T13:32:08.637 回答
0

也许不是你的问题!没有人能够在 Facebook 上发帖、点赞或评论。这可能是原因……也许它会在一个小时内再次正常工作!

于 2013-10-21T13:45:44.560 回答
0

要获取用户信息,请使用 Facebook 图形 API

请看看这个https://developers.facebook.com/docs/ios/ios-sdk-tutorial/

于 2013-10-21T13:20:18.453 回答