1

虽然我正在尝试 FBLoginView 不工作。单击该按钮时甚至没有显示任何响应。这是我使用的代码:

#import <FacebookSDK/FacebookSDK.h>
@interface myaccount ()<FBLoginViewDelegate>


- (void)viewDidLoad
{
FBLoginView *loginview =[[FBLoginView alloc] init];
loginview.frame = btn1.frame;
for (id obj in loginview.subviews)
{
    if ([obj isKindOfClass:[UIButton class]])
    {
        btn1 =  obj;
        [btn1 setBackgroundColor:UIColorFromRGB(0x3b5999)];
        [btn1 sizeToFit];
    }

}
loginview.delegate = self;
[scrol addSubview:loginview];
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                        user:(id<FBGraphUser>)user 
{
logu.name = [NSString stringWithFormat:@"%@!", user.first_name];
logu.profilePic.profileID = user.id;
profilePicker.profileID = user.id;
self.loggedInUser = user;
}
}

请帮我整理一下?

4

1 回答 1

0
  • 您可以通过使用 Graph Api 在您的应用程序中实现 facebook。

  • 创建 Graph api 对象并设置权限,如 NSString *client_id = @"124262614407976";

    如果(可达性标志==真){

    @try {
        self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];
    
      [self.fbGraph authenticateUserWithCallbackObject:self 
         andSelector:@selector(fbGraphCallback:)   andExtendedPermissions:@"user_photos,user_videos,
    

    publish_stream,offline_access,user_checkins,friends_checkins" and SuperView:self.window];

    }
    

    @catch (NSException *异常) {

    // NSLog(@"网络不可用 %@",exception.userInfo); } @最后 {

    }

    }

-- 检查后回调。- (void)fbGraphCallback:(id)sender {

if ( (fbGraph.accessToken == nil) || ([fbGraph.accessToken length] == 0) ) {

NSLog(@"You pressed the 'cancel' or 'Dont Allow' button, you are NOT logged  into   Facebook...I require you to be logged in & approve access before you can do anything useful....");

    //restart the authentication process.....
    [fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:)
                         andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins"];

} else
{

   // NSLog(@"------------>CONGRATULATIONS<------------, You're logged into Facebook...  Your oAuth token is:  %@", fbGraph.accessToken);

}

}

//////// 你可以找到朋友提要..

-(void)getMeFeedButtonPressed{

if(delegate.fbGraph.accessToken!=nil)
{
    NSString *customString=[NSString stringWithFormat:@"me"];
    NSLog(@"here responce is for %@",customString);

    FbGraphResponse *fb_graph_response = [delegate.fbGraph doGraphGet:customString withGetVars:nil];
    NSLog(@"getMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);



    //parse our json
    SBJSON *parser = [[SBJSON alloc] init];
    NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
    //  [facebook_response ]
    [parser release];
   // MyID=[facebook_response objectForKey:@"id"] ;
    [MyID appendString:[facebook_response objectForKey:@"id"]];
    NSLog(@"name  %@",[facebook_response objectForKey:@"name"]);


    NSString * url = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture",MyID];

    NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];

    UIImage *downloadedImage = [UIImage imageWithData:data];
    NSData *myEncodedImages = [NSKeyedArchiver archivedDataWithRootObject:downloadedImage];
    [[NSUserDefaults standardUserDefaults ] setObject:myEncodedImages forKey:@"MYFBIMAGE"];


    [self postData];


}else
{

    @try {

            [delegate.fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:)
                                 andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins,email"];

        }
        @catch (NSException *exception) {

            NSLog(@"Net not available");
        }
        @finally {

        }
}


}
于 2013-02-21T07:17:55.260 回答