Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:00:52+00:00 2026-05-28T03:00:52+00:00

I have been trying to solve this problem for three days now, it’s really

  • 0

I have been trying to solve this problem for three days now, it’s really simple for those who know the open graph api well. I’m new to Facebook integration but have some PHP experience.

Basically all I’m trying to do is retrieve the following information from users and store it in a database.

Facebook User ID:
Name
Gender
Email

I have done the user ID, name and gender by using:

$contents = file_get_contents ('https://graph.facebook.com/'.$user);
$json=json_decode($contents,true);
$userid = $json['id'];
$username = $json['name'];
$usergender = $json['gender'];
$useremail = $json['email'];

This works and I understand I need to ask for permissions to access the email which I have done using this code:

$app_id = "211665122244023";

     $canvas_page = "http://apps.facebook.com/midcitymafia/";

     $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,publish_actions";

     $signed_request = $_REQUEST["signed_request"];

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

But how do I get the access token and then use it to retrieve email from graph?

##UPDATE, THIS IS MY CURRENT CODE, STILL CAN’T SEEM TO GET IT TO WORK…

require 'src/facebook.php';
$app_id = "211665122244023";

     $canvas_page = "http://apps.facebook.com/midcitymafia/";

     $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,publish_actions";

     $signed_request = $_REQUEST["signed_request"];

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);


     if (empty($data["user_id"])) {
            echo("<script> top.location.href='" . $auth_url . "'</script>");
     } else {
         $graph = json_decode(file_get_contents("https://graph.facebook.com/".$user_id . "/?accesstoken=" .$data['access_token']));
     }

$userid = $graph->id;
$username = $graph->name;
$usergender = $graph->gender;
$useremail = $graph->email;

?>

<br>

<?php echo 'ID: ' . $userid; ?>
<br>
<?php echo 'Name: ' . $username; ?>
<br>
<?php echo 'Gender: ' . $usergender; ?>
<br>
<?php echo 'Email: ' . $useremail; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:00:52+00:00Added an answer on May 28, 2026 at 3:00 am

    signed_request contains user access_token within itself.

    In your case access_token is in $data['access_token']

    Storing user access_token isn’t a best idea since they provided for a short period of time and expired later. To get permanent access_token you need to request offline_access permission from user (I personally wouldn’t recommend it since you may achieve most things without requiring offline_access, in many cases Application access_token may fit your needs).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to solve this problem for a few days now without much
I have been trying to understand and solve this problem for the last three
I have been trying to solve this problem for several weeks now and it
I have been trying to solve this problem for a while, but couldn't with
I'm still a beginner and I have been trying to solve this problem by
I have been trying to get this seemingly simple problem fixed for about half
I have been trying to solve a PHP regular expression problem for awhile now
I have an interesting problem here I've been trying to solve for the last
I have been trying to get around this error for a day now and
I've been trying to figure this problem out for the last 2 days already,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.