perl/facebook how to get the user id from User object

234 Views Asked by At

Hi I was looking around the web, but I couldn't find any simple answers on how to get JUST the facebook id from the current user viewing my application. I understand that I need to get the User object from the Graph API and just get the id from that field. I also understand that I do not need an access token for my case. I am trying to do this in perl/mason and I was wondering if anyone could help me out with this. I am sorry if this is a duplicate, but I couldnt find that many answers out there with perl / mason

Thank you

Is there something as simple as this in perl /mason?

require 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'YOUR_APP_ID',
  'secret' => 'YOUR_APP_SECRET',
));

// Get User ID
$user = $facebook->getUser();
2

There are 2 best solutions below

0
On

Check out this

Looks like it will get you what you need.

Though I'm a bit confused what getUser() would return for an application. You've not specified anything to tell it what user you want, but I'm no facebook expert.

0
On

Regarding needing access token, Yes and no

You don't need access token to fetch current use basic info just if you use facebook javascript sdk, I guess the example above you posted is facebook php sdk which work in combination with their javascript sdk so I think function getUser actually talk to the javascript side of the SDK

see facebook javascript sdk for example on how to use it

to get user data to your perl app I suggest you use ajax call

after initiating javascript sdk, to get user id

//-> /me is for current logged user
FB.api('/me', function(response) {
    alert('Your name is ' + response.name);
    //send response to your perl app
});

Other wise authorization process is required and access token is needed.

I'm not sure if there is a perl module that integrates facebook javascript sdk with any templating / mason but I guess this isn't hard to do manually