Facebook iOS sdk to accept user id

question about Facebook sdk for iOS.

If I have an active session, how can I get only the user ID?

Is there an easy way to get this identifier without using this sample code?

if (FBSession.activeSession.isOpen) { [[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *aUser, NSError *error) { if (!error) { // I can take the user id.. } }]; } 
+7
source share
3 answers

This is the best way to get the user ID, not direct access with a dot.

 [[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *aUser, NSError *error) { if (!error) { NSLog(@"User id %@",[aUser objectForKey:@"id"]); } }]; 
+8
source
 + (NSString *)activeUserId { return [FBSDKAccessToken currentAccessToken].userID; } 

if you are already logged in to facebook.

+6
source
 [FBRequestConnection startWithGraphPath:@"/me" parameters:nil HTTPMethod:@"GET" completionHandler:^( FBRequestConnection *connection, NSDictionary *result, NSError *error ) { /* handle the result */ _fbId = [result objectForKey:@"id"]; }]; 
+1
source

All Articles