tags:

views:

173

answers:

1

If user is not logged to facebook then clicking on Like Button opens a popup window prompting for user to login. I don't want that popup to display - hence the best would be to not show Like button for visitors that are not logged to Facebook.

Is it possible?

+1  A: 

Yes and no. It is possible when your facebook application is not shown in a tab because in a tab facebook runs no javascript and no user information is passed until the user clicked somewhere.

If you are writing a "real" facebook app, you could try the following code, I do this 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", a guest is viewing the application.

Blauesocke
Sorry. I should have made myself more clear. I am not writing a facebook app. It's a like button that can be embeded on any website - (http://developers.facebook.com/docs/reference/plugins/like ) you can embed the button using IFRAME (which I assume you can't do anything with) or using XFBML which might be possible to alter with javascript somehow?
Janusz

related questions