What potential security risks are involved in accessing user information without authorization in a Facebook app?

Accessing user information without authorization in a Facebook app can lead to serious security risks such as exposing sensitive personal data, violating privacy laws, and damaging the reputation of the app and its developers. To prevent this, it is essential to always obtain explicit consent from users before accessing their information and to strictly adhere to Facebook's API guidelines and security best practices.

// Check if user has authorized the app before accessing their information
if ($fb->getUser() && $fb->isAuthorized()) {
    // Proceed with accessing user information
    $user_info = $fb->getUserInfo();
} else {
    // Redirect user to authorization page
    header("Location: " . $fb->getAuthorizationUrl());
    exit();
}