Facebook Login

Before making any calls to one of our service, you'll need to acquire an access token from your user. The code sample below shows how to authenticate the user.

In this example, you can see the email permissions being requested:

// trigger the login flow
fbgLoginScope loginScopes[1] = { 
  fbgLoginScope::email 
};
  
fbg_Login_WithScopes(
  1,
  loginScopes
);

For a new player to your game, this will trigger a login dialog. For existing players, this will return the app-scoped Facebook User ID and user access token. The code below describes how to handle the Login message in your game loop to extract this information.

while ((message = fbg_PopMessage()) != nullptr) {
  switch (fbg_Message_GetType(message)) {
  	// ...
    case fbgMessage_AccessToken: {
      auto accessTokenHandle = fbg_Message_AccessToken(message);
      auto isValid = fbg_AccessToken_IsValid(accessTokenHandle);
      if (!isValid) {
        // user not logged in
        break;
      }

      auto userid = fbg_AccessToken_GetUserID(accessTokenHandle);

      char token_string[512];
      auto size = fbg_AccessToken_GetTokenString(accessTokenHandle, token_string, 512);
      auto expiration_timestamp = fbg_AccessToken_GetExpirationTimestamp(accessTokenHandle);

      fbgLoginScope permissions[512];
      auto permissionCount = fbg_AccessToken_GetPermissions(accessTokenHandle, permissions, 512);

      printf(
        "User ID: %lld\nAccess Token: %s\nExpiration Timestamp: %lld, Permission Count: %d\nPermissions: ",
        (long long)userid,
        token_string,
        (long long)expiration_timestamp,
        permissionCount
      );
  
      for (int i = 0; i < permissionCount; i++) {
        printf("%s", fbgLoginScope_ToString(permissions[i]));
      }
      printf("\n");
      break;
  }
  fbg_FreeMessage(message);
}

More information: