Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook iOS sdk to take user id

a question about Facebook sdk for iOS.

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

Is there a simple way to obtain this id without use this example code?

if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:
         ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *aUser, NSError *error) {
             if (!error) {
                 // I can take the user id..
             }
         }];
    }
like image 525
Safari Avatar asked Jun 01 '13 12:06

Safari


3 Answers

+ (NSString *)activeUserId {
    return [FBSDKAccessToken currentAccessToken].userID;
}

if you are already logged in on facebook.

like image 54
bonpv Avatar answered Oct 05 '22 05:10

bonpv


This is best way to take user id, instead of directly access using dot.

[[FBRequest requestForMe] startWithCompletionHandler:
         ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *aUser, NSError *error) {
             if (!error) {
                 NSLog(@"User id %@",[aUser objectForKey:@"id"]);
             }
         }];
like image 35
Mani Avatar answered Oct 05 '22 06:10

Mani


[FBRequestConnection startWithGraphPath:@"/me"
                             parameters:nil
                             HTTPMethod:@"GET"
                      completionHandler:^(
                                          FBRequestConnection *connection,
                                          NSDictionary *result,
                                          NSError *error
                                          ) {
                          /* handle the result */
                          _fbId = [result objectForKey:@"id"];
                      }];
like image 24
Cayke Prudente Avatar answered Oct 05 '22 04:10

Cayke Prudente