perl - cant get email with Net::Facebook::Oauth2 -
$fb = net::facebook::oauth2->new( application_id => 'your_application_id', application_secret => 'your_application_secret', callback => 'http://yourdomain.com/facebook/callback' ); $access_token = $fb->get_access_token(code => $cgi->param('code')); ###save token in database or session ##later on application can use verifier code comunicate ##with facebook on behalf of user $fb = net::facebook::oauth2->new( access_token => $access_token ); $info = $fb->get( 'https://graph.facebook.com/me' ##facebook api url ); print $info->as_json;
when try print json format of response missing email followin output
{"id":"100001199655561","name":"pavan kumar tummalapalli","first_name":"pavan","middle_name":"kumar","last_name":"tummalapalli","link":"http:\/\/www.facebook.com\/pavan.tummalapalli","username":"pavan.tummalapalli","hometown":{"id":"125303864178019","name":"kodada, india"},"location":{"id":"115200305158163","name":"hyderabad, andhra pradesh"},"favorite_athletes":[{"id":"108661895824433","name":"ab de villiers"}],"education":[{"school":{"id":"129163957118653","name":"city central school"},"type":"high school"},{"school":{"id":"124833707555779","name":"anurag engineering college"},"year":{"id":"136328419721520","name":"2009"},"type":"college"}],"gender":"male","timezone":5.5,"locale":"en_us","verified":true,"updated_time":"2012-12-30t09:13:54+0000"}
'https://graph.facebook.com/me?fields=email
the following reponse as
{"error":{"message":"an active access token must used query information current user.","type":"oauthexception","code":2500}}
probably not have adequate permission access data. code provided doesn't indicate if have requested email permission on authorization process i'm guessing didn't request it.
when redirect user auth dialog, https://www.facebook.com/dialog/oauth/?client_id=your_app_id&redirect_uri=your_redirect_url&state=your_state_value&scope=comma_separated_list_of_permission_names , have specify scope=email acquire permission access email field.
to check if have permission, can access url below , see if have it.
my $permission_ref = $fb->get( 'https://graph.facebook.com/me/permissions' );
the returning value should below.
{ "data": [ { "installed": 1, "email": 1 } ] }
if includes email, have permission access user email.
if not you'll have request permission it. net::facebook::oauth2, can generate dialog url below.
$fb = net::facebook::oauth2->new( application_id => 'your_application_id', application_secret => 'your_application_secret', callback => 'http://yourdomain.com/facebook/callback' ); $url = $fb->get_authorization_url( scope => ['email'], );
redirect user url , you'll permission.
and if have email permission, email not returned because of bug. might want check bug report, "api call /me missing user's email email permission."
Comments
Post a Comment