1

I haven't changed this code in our code base for 250 days and the Facebook Graph API is returning a 400 Error. Its a small php service that returns the latest tweets of a given user.

$appID = '**********';
$appSecret = '***********';

$feed = $_GET['username']; // PAGE ID
$maximum = $_GET['numposts']; // NUMBER OF POSTS

$authentication = file_get_contents("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={$appID}&client_secret={$appSecret}");
$response = file_get_contents("https://graph.facebook.com/{$feed}/posts?{$authentication}&limit={$maximum}&format=json&fields=id,message,created_time,link,full_picture,shares");

// ACCESS CONTROL
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');

// CACHE
$seconds_to_cache = 225; // 3 MINS
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");

header('Content-Type: application/json;  charset=UTF-8');
echo $response; 

and the error returned is

failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

There are two trails of thought:

  1. We're over the limit on our requests.
  2. Facebook Graph API have changed their endpoint (although no information from there).

I have tried regenerating the tokens and updating but with no luck.

WebDevDanno
  • 1,122
  • 2
  • 22
  • 50
  • https://developers.facebook.com/docs/apps/changelog Version 2.2 looks suspect considering support ended 3 days ago: v2.2 /v2.2/{object} October 30, 2014 March 25, 2017 – Matt Mar 28 '17 at 21:44
  • What is the error message that Facebook send back? – WizKid Mar 28 '17 at 21:46
  • @mkaatman I think you might be right. I think I am making `unversioned` requests. That ties up to when we started receiving errors. How do I make versioned requests in the context of my code? – WebDevDanno Mar 28 '17 at 21:58
  • Not sure I try to avoid facebook like the plague. – Matt Mar 28 '17 at 22:06

0 Answers0