获取Facebook帐户详细信息

时间:2012-06-28 09:55:12

标签: iphone ios5 sharekit

我正在使用Sharekit for Facebook和Twitter,我想获取Facebook帐户详细信息,如用户ID,个人资料名称等。请提供您的建议和帮助。我之前有详细信息,但现在我无法检索它

请找到以下代码,

 if ([[NSUserDefaults standardUserDefaults] objectForKey:@"kSHKFacebookUserInfo"]){
            NSDictionary *facebookUserInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"kSHKFacebookUserInfo"];
           fbUseremail = [facebookUserInfo objectForKey:@"email"];
            NSLog(@"FBid-- %@",fbUseremail);
        }
        if ([[NSUserDefaults standardUserDefaults] objectForKey:@"kSHKFacebookUserInfo"]){
            NSDictionary *facebookUserInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"kSHKFacebookUserInfo"];
            fbUserName = [facebookUserInfo objectForKey:@"name"];
            NSLog(@"FBName-- %@",fbUserName);
        }

现在它因为facebookUserInfo为NULL而崩溃。

2 个答案:

答案 0 :(得分:1)

我刚试了一下这个演示应用程序,效果很好。要找到,发生了什么,你可以在SHKFacebook.m - (void)request:(FBRequest *)fbRequest didLoad:(id)result,第411行休息一下。现在你可以看到,你从Facebook得到了什么。

要获取用户信息,您必须先从Facebook获取信息:

SHKItem *item = [[SHKItem alloc] init];
item.shareType = SHKShareTypeUserInfo;
[SHKFacebook shareItem:item];

答案 1 :(得分:0)

您可以使用Facebook Graph API获取用户名。将方法添加到FBConnect包的FBSession.m类。

 #import "JSON.h"

...........

static NSString *const kGraphAPIURL = @"https://graph.facebook.com/";
//static NSString *const kFBGraphAPIUserName = @"name";

...........

// Get user name via Facebook GraphAPI.

- (NSString *)getUserNameByUID:(FBUID)aUID {

 NSString *userName_ = nil;

 NSURL *serviceUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%qi", kGraphAPIURL, aUID]];

 [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

 NSError *error = nil;
 NSString *jsonString = [NSString stringWithContentsOfURL:serviceUrl encoding:NSUTF8StringEncoding error:&error];

 if (error != nil) {
   NSLog(@"######### error: %@", error);
 }

 if (jsonString) {

    // Parse the JSON into an Object and 
    // serialize its object to NSDictionary
    NSDictionary *resultDic = [jsonString JSONValue]; // U have resultDic with information

    //if (resultDic) {
        //userName_ = [resultDic valueForKey:kFBGraphAPIUserName];
    //}
 }

 [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

 return userName_;
}