1

I'd like to get the Facebook id from ShareKit anyone have any idea? There's this reference but I still dont get it. Reference

TIA

Community
  • 1
  • 1
ordinaryman09
  • 2,761
  • 4
  • 26
  • 32

2 Answers2

1

ShareKit has a built in method for this:

[SHKFacebook getUserInfo];

I prefer calling it using my own member variable and checking return values inside of SHKShareDelegate callback:

SHKItem *item = [[[SHKItem alloc] init] autorelease];
item.shareType = SHKShareTypeUserInfo;
[self.shkFacebook setItem:item];
[self.shkFacebook share];

Here is the callback into delegate method shareFinishedSending():

if ([sharer isEqual:self.shkFacebook] &&
    sharer.item.shareType == SHKShareTypeUserInfo) {
    NSDictionary *facebookUserInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"kSHKFacebookUserInfo"];
    NSLog(@"id: %@", [facebookUserInfo objectForKey:@"id"]);
    NSLog(@"name: %@ %@", [facebookUserInfo objectForKey:@"first_name"], [facebookUserInfo objectForKey:@"last_name"]);
    NSLog(@"email: %@", [facebookUserInfo objectForKey:@"email"]);
}
1

I got this by using the request:-

Facebook *facebook = [[Facebook alloc] initWithAppId:SHKCONFIG(facebookAppId) 
                                     urlSchemeSuffix:SHKCONFIG(facebookLocalAppId) 
                                         andDelegate:nil];
// ... do authorization stuff

// when authorized...
[facebook requestWithGraphPath:@"me" andDelegate:self];

and implementing the delegate callback in the same file:-

- (void)request:(FBRequest *)request didLoad:(id)result
{
    NSString *fbid = [result objectForKey:@"id"];
    NSLog( @"facebook ID %@", fbid );
}

This does work, but I've no idea if this is the recommended technique, since it's the first time I've used sharekit. It seems odd to me the singleton method [SHKFacebook facebook] is private and you have to instantiate an object yourself.

Echelon
  • 7,306
  • 1
  • 36
  • 34