2

I am using Sharekit for Facebook and Twitter and i would like to get the Facebook account details like User id,Profile Name etc.please give your suggestions and help.I had got the details before but now i am not able to retrieve it.

Please find the code below,

 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);
        }

Now it gets crashed as the facebookUserInfo is NULL.

ishhhh
  • 647
  • 2
  • 11
  • 29

2 Answers2

1

I have just tried it with the demo app, and it worked well. To find, what is going on, you can make a break in SHKFacebook.m - (void)request:(FBRequest *)fbRequest didLoad:(id)result, line 411. Now you can see, what are you getting back from Facebook.

To get user info, you must first fetch it from Facebook:

SHKItem *item = [[SHKItem alloc] init];
item.shareType = SHKShareTypeUserInfo;
[SHKFacebook shareItem:item];
Vilém Kurz
  • 3,401
  • 2
  • 34
  • 43
0

You can use Facebook Graph API for get username. Add method bellow to FBSession.m class of FBConnect package.

 #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_;
}
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132