Is it possible to display the Facebook Like button only if the user is logged into Facebook?

If the user is not registered with facebook, then clicking on the Like button opens a popup asking for the user's login. I don't want this popup to be displayed - hence, it would be best not to show the Like button to visitors who are not logged into Facebook.

Is it possible?

+2


a source to share


1 answer


Yes and no. This is possible if your facebook app is not showing in the tab because there is no javascript in the facebook tab and no user information is passed until the user clicks somewhere.

If you are writing a "real" facebook application you can try the following code, I am doing it in PHP like this:



// Get user id
public function getUserId()
{
    $user_id = 0;
    try
    {
        $user_id = $this->facebook->api_client->users_getLoggedInUser();
    }
    catch(Exception $e)
    {
        $user_id = 0;
    }   

    return $user_id;
}

      

If this code returns "0", the guest is viewing the application.

+2


a source







All Articles