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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:01:35+00:00 2026-06-03T20:01:35+00:00

My web pages uses PHP to do a FQL request that obtains the logged

  • 0

My web pages uses PHP to do a FQL request that obtains the logged in user’s friend count, here’s the code:

$graph = 'https://graph.facebook.com/fql?q=';
$graph .= 'SELECT+friend_count+FROM+user+WHERE+uid%3Dme%28%29';
$graph .= '&access_token=' . $access_token;
$result = file_get_contents($graph);

About 80% of the time this works fine, but sometimes I get a 400 Bad Request. I notice that this seems to be caused by the ampersand that separates the ‘q’ from the ‘access_token’ is being escaped; i.e. I get this (doesn’t work):

https://graph.facebook.com/fql?q=SELECT+friend_count+FROM+user+WHERE+uid%3Dme%28%29&access_token=AAAF8VR3YZCpQBAGiX16jvZAwaEciTwZB1QZAaUjcjy82Ce7Ov7nPqNxjsKM1SAZASGVcZCJ80R9KJZBJYrjKmsDVK6YNrPGA7plPVuwCFZCaOwZDZD

Instead of this (works – same request but ‘&’ has been replaced by ‘&’):

https://graph.facebook.com/fql?q=SELECT+friend_count+FROM+user+WHERE+uid%3Dme%28%29&access_token=AAAF8VR3YZCpQBAGiX16jvZAwaEciTwZB1QZAaUjcjy82Ce7Ov7nPqNxjsKM1SAZASGVcZCJ80R9KJZBJYrjKmsDVK6YNrPGA7plPVuwCFZCaOwZDZD

I tried to adjust my code accordingly so that the PHP explicitly tells the string to replace the escaped ampersand but to no avail:

$graph = 'https://graph.facebook.com/fql?q=';
$graph .= 'SELECT+friend_count+FROM+user+WHERE+uid%3Dme%28%29';
$graph .= '&access_token=' . $access_token;
$result = file_get_contents($graph);
$graphNoEscape = str_replace('&', '&', $graph);
$result = file_get_contents($graphNoEscape);

Does anybody know the solution to the problem? It’s annoying that this code works sometimes, but not all the time!

  • 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-03T20:01:36+00:00Added an answer on June 3, 2026 at 8:01 pm

    For anybody that finds this and is having the same problem, this is how I solved it:

    First, I told server to use one php.ini in the public_html/www folder, PHP version 5.3.

    Then I edited my code as follows:

    $graph = 'https://graph.facebook.com/fql?q='; 
    $graph .= urlencode('SELECT friend_count FROM user WHERE uid = me()');
    $graph .= '&access_token='.$access_token; 
    $graphNoEscape = str_replace('&', '&', $graph); 
    $file_contents = file_get_contents($graphNoEscape); 
    $fql_result = json_decode($file_contents); 
    $friend_count = mysql_real_escape_string($fql_result->data[0]->friend_count);
    

    Admittedly I may have over done it with the str_replace(), but it works none-the-less 🙂

    Hope this can help someone.

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

Sidebar

Related Questions

I have a php web page that now uses custom error pages when a
I am writing a web page that uses some php files. The php isn't
I have a web page that uses three controls to allow a user to
Guys, has anyone been able to remotely debug a PHP Web page that uses
I have created a word dictionary that uses PHP and XML. The user enters
I have a simple image upload script that uses SimpleImage.php (http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/) to resize and
I have a web page which uses in PHP and a jQuery DataTable to
I have a web page that uses cross page posting to post to a
I have a web page that uses jquery ajax to grab the table markup
Let's assume I browse a specific web page that uses JavaScript to update its

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.