1

My issue is that the $info variable which requests user data is not providing the email. You can see in my fblogin() code I use the email scope. If you look here: debug($info->as_json); it only contains {"Name":"somename","id":"someid"}

I tried dumping the $access_data as:

 foreach $key (keys %access_data) {
   debug("$key $access_data{$key}");
 }

but that didn't seem to work correctly.

Here's my debug function:

sub debug {
  my $str=shift;
  my @lt=localtime(time());
  my $ts=sprintf("%d%2.2d%2.2d %2.2d:%2.2d",@lt[5]+1900,@lt[4]+1,@lt[3],@lt[2],@lt[1]);
  open(FD,">>/file");
  print FD "[$ts] $str\n";
  close(FD);
}

Any help would be greatly appreciated

sub fblogin(){
  my $fb = Net::Facebook::Oauth2->new(
    application_id     => 'XXXX',
    application_secret => 'XXXX',
    callback           => 'URL'
  );
  # get the authorization URL for your application
  my $url = $fb->get_authorization_url(
    scope   => [ 'email' ],
    display => 'page'
  );
  print "Location: $url\n\n";
}

sub fbcallback(){
   my $fb = Net::Facebook::Oauth2->new(
     application_id     => 'XXXX',
     application_secret => 'XXXX',
     callback           => 'URL'
   );
   my $query=new CGI;
   my $code = $query->param('code');
   my ($unique_id, $access_token);
   try {
     $access_token = $fb->get_access_token(code => $code); # <-- could die!

     # Facebook tokens last ~2h, but you may upgrade them to ~60d if you want:
     $access_token = $fb->get_long_lived_token( access_token => $access_token );

     my $access_data = $fb->debug_token( input => $access_token );
     if ($access_data && $access_data->{is_valid}) {
        $unique_id = $access_data->{user_id};
        # you could also check here for what scopes were granted to you
        # by inspecting $access_data->{scopes}->@*
        my $info = $fb->get(
                'https://graph.facebook.com/v3.1/me'   # Facebook API URL
        );
        debug($info->as_json);
      }
   } catch {
     # handle errors here!
   }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
somejkuser
  • 8,856
  • 20
  • 64
  • 130
  • Try using the `fields` query parameter in the URL of the `get` call. For example, this URL `https://graph.facebook.com/{your-user-id}?fields=email` might work according to the [documentation](https://developers.facebook.com/docs/graph-api/using-graph-api) – Håkon Hægland Oct 04 '19 at 06:05
  • Possible duplicate of [Facebook only returning name and id of user](https://stackoverflow.com/questions/31692355/facebook-only-returning-name-and-id-of-user) – 04FS Oct 04 '19 at 07:26

0 Answers0