2012-06-28 74 views
2

我正在使用Facebook和Twitter的Sharekit,我想獲得Facebook帳戶的詳細信息,如用戶名,個人資料名稱等。請給予您的建議和help.I已經得到的細節之前,但現在我無法檢索它。獲取Facebook帳戶詳細信息

請找到下面的代碼,

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。

+0

請參考以下鏈接https://github.com/ShareKit/ShareKit/issues/184 – Ramz

+0

@RamkumarThiyyakat我想,解決方案,但沒有改變:( – ishhhh

回答

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_; 
} 
1

我剛剛與試了一下演示應用程序,它運行良好。要找到,發生了什麼事情,你可以在SHKFacebook.m - (void)request:(FBRequest *)fbRequest didLoad:(id)result,第411行中斷。現在你可以看到,你從Facebook得到什麼。

要獲得用戶信息,您必須首先從Facebook獲取它:

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