1

I know there are many Q&A on here about this but I can't seem to make sense of them because they don't show full code examples or are for doing something different than what I'm trying to do.

I have a simple facebook welcome-test tab. Not a canvas app. I want to be able to get the users id but have to make it prompt them for access to that info before it will show up in the signed request.

So what I'm looking for is a code example for a simple welcome tab. I don't need a login page or anything like that since this will be in the fan content page so they will have to be logged in already. I just want that dialog box to popup asking them for permission so I can get the userid.

Thanks

Edit: I wanted to add that I just figured out my problem but it's not really an answer to this question. I figured out how to get the user id without asking the user for permission to access their profile. It was as easy as adding this code to the page and it works in a tab and canvas app the same way. getUser() by its self returns 0 but since the user is already logged in to be seeing this content, when getUser() returns 0, then the code simply gets the user id from the API method. Now that I finally figured this out it seems simple.

$session = $facebook->getUser();

if (!$session) {

    $url = $facebook->getLoginUrl(array(
        'canvas' => 1,
        'fbconnect' => 0
    ));

    echo "<script type='text/javascript'>top.location.href = '$url';</script>";

} else {

    try {

        $uid = $facebook->getUser();
        $me = $facebook->api('/me');

        $updated = date("l, F j, Y", strtotime($me['updated_time']));

        echo "Hello " . $me['name'] . "<br />";
        echo "You last updated your profile on " . $updated;

    } catch (FacebookApiException $e) {

        echo "Error:" . print_r($e, true);

    }
}

I'd still like to know if there is a way to make the extended permissions dialog show for a tab app so it will be good to see solutions for php sdk.

isimmons
  • 2,016
  • 2
  • 20
  • 32

2 Answers2

0

you need to prompt them for allowing your application to pull data on the user

this can be done using the JS SDK's function FB.login(). you can have more details in the facebook documentation : http://developers.facebook.com/docs/reference/javascript/FB.login/

notice that the popup can be opened only on mouseclick or keyup events - otherwise popup blockers will block it.

you will also have to set a domain and site url to the application in the developers site, and init the facebook js library (the loading paragraph in - http://developers.facebook.com/docs/reference/javascript/)

<div onclick="login();">click here to login</div>

<script type="text/javascript">
function afterLogin(){
   alert("user logged");
}

function login(){
    FB.getLoginStatus(function(response){
        if(response.status=="connected")
        {
            afterLogin();
        } else {
            FB.login(function(response){
                if(response.status=="connected")
                {
                afterLogin();
                }
            });
        }
    });
}
</script>
Yaron U.
  • 7,681
  • 3
  • 31
  • 45
  • Thanks Yaron Uliel, I want to do this with the php sdk if it's possible. I'm going to edit the question because as it turns out, I actually don't need the user to allow access to an app to get the user id. There is a lot of confusing half written info on these topics on the Internet so I was under the impression that I had to get user permission to get their user id. But I just managed to figure it out. – isimmons Feb 25 '12 at 16:23
-1

I don't think facebook allows this... Facebook does not want a user's tab to be able to detect who is looking at it, and possibly displaying information to a user's friends that isn't displayed to the user.

I can be wrong :)

jribeiro
  • 3,387
  • 8
  • 43
  • 70
  • This person seems to be trying to do what I am trying but I have the same problem he is having. http://stackoverflow.com/questions/7278378/facebook-graph-api-page-tab-extra-permissions I get the facebook logo when clicking on the login link but don't see how the person solved their problem. I'm using php sdk, not javascript so the part on that link about javascript doesnt' apply here. – isimmons Feb 25 '12 at 16:00
  • I added the welcome-test on facebook as a canvas app and it behaves exactly the same way but with a bigger iframe so maybe if I can figure out how to prompt users for access to userid via the canvas, then I can try to apply the same code to the tab. – isimmons Feb 25 '12 at 16:07