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 8039543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:36:15+00:00 2026-06-05T03:36:15+00:00

I am trying to get the Facebook access tokens useing the bellow code: I

  • 0

I am trying to get the Facebook access tokens useing the bellow code:
I did create my own function before but it came back with the same error and i can’t work out what is the problem.

function getAccessToken(){
        $app_id = FB_APP_ID;
        $app_secret = FB_SECRET_ID;
        $my_url = FB_PAGE_URL;
        $code = $_REQUEST["code"];   


        if(empty($code)) {
       $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
       $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
         . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
         . $_SESSION['state'];

       echo("<script> top.location.href='" . $dialog_url . "'</script>");
     }      
    if($_REQUEST['state'] == $_SESSION['state']) {
       $token_url = "https://graph.facebook.com/oauth/access_token?"
         . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
         . "&client_secret=" . $app_secret . "&code=" . $code;

       $response = file_get_contents($token_url);
       $params = null;
       parse_str($response, $params);

       $graph_url = "https://graph.facebook.com/me?access_token=" 
         . $params['access_token'];

       $user = json_decode(file_get_contents($graph_url));
       echo("Hello " . $user->name);
     }
     else {
       echo("The state does not match. You may be a victim of CSRF.");
     }
}

Taken from Server-Side Authentication but i keep getting this error:

    Warning: file_get_contents(https://graph.facebook.com/oauth/access_token?
client_id=ID HERE&redirect_uri=URLHERE&cli
ent_secret=SECRECT&code=AQCI5rNgw9zCPHWGozeT59asg7_022u5tVc5XSef49BiX
IaF5_MAMqFwsqOAquUHgjOu_99ONwUV6IC7k-jV6DsWf9ni3jm8t59aHCBp1jrFaDthPbIKLNLQ-
fZgB5MLh1le5BAPKj_l57jhTLTBfOdxRU30mFCMYzMch8MYFpCmJ9GrjSSGwt0OKb_LNqMoRf8) [function.file-
get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

Anyone know the fix?

  • 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-06-05T03:36:16+00:00Added an answer on June 5, 2026 at 3:36 am

    I have managed to fix this issue using the PHP SDK,
    and after a long battle with the SDK to get it to do what i wanted.

    I did also open another question with the same idea but with another problem.
    This problem has now been solved.

    Check out this question for the answer to this problem: Facebook Access Token Server Side Authentication

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

Sidebar

Related Questions

Hello i'm trying to use facebook server-side authenticaion to get the access token but
I am trying to get access token using from facebook graph API in my
I'm trying to get JSON data from facebook using the following code: var getFriends
I am trying to get if user is logined in facebook, if yes then
I'm trying to get an Android app to post highscores to Facebook, similar to
I'm trying to reverse engineer how facebook handles their notifications, where when you get
Trying to get comfortable with jQuery and I have encountered some sample code that
I've encountered several issues while trying to get Facebook's Graph API work in IE.
I'm trying to get my facebook graph oauth setup using javascript's window location methods.
I am trying to post to my facebook page wall using curl but i

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.