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

  • Home
  • SEARCH
  • 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 1032275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:03:17+00:00 2026-05-16T14:03:17+00:00

I’ve been going through FB docs but I think I am totally lost now.

  • 0

I’ve been going through FB docs but I think I am totally lost now. My task is quite simple: I need to have an “import” link, user clicks it and receives FB popup where he authorizes the site, user is redirected back to my site, I access user’s FB profile and retrieve some data. Also: I need to access and retrieve profile in PHP.

The first part goes well. I created mysite.com?page=import link which opens in popup and then redirects to https://graph.facebook.com/oauth/authorize?…
User then allows access and the popup is redirected back to mysite.com?…#access_token=…&expires_in=4031
Then I am going to close the popup and instead refresh the parent window that opened this popup by redirecting it to something like this mysite.com?page=register&access_token=…&expires_in=4031
Then I was going to use their PHP SDK hoping that it can take this access token and allow me to get user’s data. However I have no luck so far. I’ve tried lots of things and went through facebook.php but can’t see a solution. Please let me know how to do this: authorize user in a popup and then gather the profile data in php.

  • 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-16T14:03:17+00:00Added an answer on May 16, 2026 at 2:03 pm

    here is your working example.
    it has a redirect and works entirely in php, i didnt do javascript beacuse this is easier and faster to write.
    the main difference is that the returned code after the authorization page is only a code which allows you to fetch the actual access token incombination with your client secret.
    otherwise anyone could get an access token for yuor application or you would have to pass your secret token in the url.
    thats the reason for the second step.
    in javascript we dont need that because facebook only redirects back to a whitelisted domain
    and as the access token is in the url fragment after the # tag the server cant access it, only the client. and this is ensured to be yours erver as your domain must be whitelisted.
    but it needs more client interaction…
    well anyway. you can use the code i wrote for yuo and you can also do it in a popup. you just have to pass your variables to the form or whatever you are doing but this shouldnt be a problem. i did it this way because you said you needed it in php. a good javascript example can be found on the facebook connect page here: http://developers.facebook.com/docs/guides/web#login

    any questions? comment!

    ps: i put the @ sign before the file_get_contents function because you might geht ssl errors, you should actually use curl for that and do error handling!

    save this file as whatever.php to your server, check the 4 config variables in the top and hit it

    <?
    // your app id
    $app_id = "123";
    
    // your secret token
    $mysecret = '***';
    
    // your website correctly set up in facebook app config
    $redirecturl = "http://www.yourdomain.com/whatever/thisfile.php?action=authorized";
    
    // what you want to fetch
    $scopes = array('email','user_interests'); // whatever you want
    
    
    if($_GET['action'] == 'authorize') {
        $url = "https://graph.facebook.com/oauth/authorize?client_id=".$app_id."&redirect_uri=";
        $url .= urlencode($redirecturl);
        $url .= "&display=popup";
        $url .= "&scope=".implode(',',$scopes);
        header("Location: $url");
        exit();
    } else if($_GET['action'] == 'authorized') {
        $code = $_GET['code'];
        $tokenurl = 'https://graph.facebook.com/oauth/access_token'.
        '?client_id='.$app_id .
        '&redirect_uri='.urlencode($redirecturl).
        '&client_secret='.$mysecret.
        '&code='.$code;
        $token = @file_get_contents($tokenurl);
        $token = preg_match('/access_token=(.*)&/',$token,$extracted_token);
        $token = $extracted_token[1];
        $dataurl = 'https://graph.facebook.com/me?access_token='.$token;
        $result = @file_get_contents($dataurl);
        $data = json_decode($result);
        echo "<pre>".print_r($data,true)."</pre>";
    } else {
        ?><a href="?action=authorize">click here to immport your data</a><?
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.