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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:53:22+00:00 2026-05-28T06:53:22+00:00

file_get_contents not working for fetching fata from facebook using batch requests.Am using the code

  • 0

file_get_contents not working for fetching fata from facebook using batch requests.Am using the code below:

  $url='https://graph.facebook.com/?batch=[{ "method": "POST", "relative_url":"method/fql.query?query=SELECT+first_name+from+user+where+uid=12345678"}]&  access_token=xxxxxxx&method=post';
 echo  $post = file_get_contents($url,true);
it produces 
    Warning: file_get_contents(graph.facebook.com/?batch=[{ "method": "POST", "relative_url": "method/fql.query?query=SELECT+first_name+from+user+where+uid=12345"}]&access_to‌ ​ken=xxxx&method=post): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/user/workspace/fslo/test.php on line 9
  • 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-28T06:53:23+00:00Added an answer on May 28, 2026 at 6:53 am

    I would say the most likely answer to this is that you need to pass the URL values through urlencode() – particularly the JSON string.

    Also, you should be POSTing the data.

    Try this code:

    NB: I presume you are building the URL from several variables. If you edit the question with your actual code, I will provide a solution using that code

    <?php
    
      $baseURL = 'https://graph.facebook.com/';
    
      $requestFields = array (
        'batch' => '[{"method":"POST","relative_url":"method/fql.query?query=SELECT+first_name+from+user+where+uid=12345678"}]',
        'access_to‌ken' => 'whatever'
      );
      $requestBody = http_build_query($requestFields);
    
      $opts = array(
        'http'=>array(
          'method' => 'POST',
          'header' => "Content-Type: application/x-www-form-urlencoded\r\n"
                    . "Content-Length: ".strlen($requestBody)."\r\n"
                    . "Connection: close\r\n",
          'content' => $requestBody
        )
      );
    
      $context = stream_context_create($opts);
    
      $result = file_get_contents($baseURL, FALSE, $context);
    

    A “more standard” way to do this these days is with cURL:

    <?php
    
      $baseURL = 'https://graph.facebook.com/';
    
      $requestFields = array (
        'batch' => '[{"method":"POST","relative_url":"method/fql.query?query=SELECT+first_name+from+user+where+uid=12345678"}]',
        'access_to‌ken' => 'whatever'
      );
      $requestBody = http_build_query($requestFields);
    
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $baseURL);
      curl_setopt($ch, CURLOPT_POST, TRUE);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/x-www-form-urlencoded',
        'Content-Length: '.strlen($requestBody),
        'Connection: close'
      ));
    
      $post = curl_exec($ch);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code is using file_get_contents() to make GET requests to an API endpoint. It
This is my code, it will echo Not working $f = file_get_contents(http://www.google.com); $text =
From one apache server file_get_contents returns the contents of a url straight away. On
I get a page using file_get_contents from a remote server, but I want to
I am using file_get_contents through proxy to fetch a webpage. This setup was working
how to grab facebook username? using preg_matching? this is my sample code! <?php $page
I am working on FaceBook Graph API. 1. I am able to connect with
Logically I am trying to figure out why my code is not working. foreach($list
I'm using file_get_contents('mysourcefile.html') to load the contents of mysourcefile.html into mysql db. I have
Currently I'm using file_get_contents() to submit GET data to an array of sites, but

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.