0

Following the Facebook PHP API Tutorial, I wrote a function which post a link to my facebook page.

From this page I got how to generate the Page Access Token

As you can see from the feed page description, there is a backdated_time parameter (available only for page posts, not user posts) which allow you select a time in the past to back-date the post.

Here is the body of my function:

require_once(dirname(__FILE__) . "/facebook-php-sdk/facebook-php-sdk-v4-4.0-dev/autoload.php");

use Facebook\FacebookSession;

use Facebook\FacebookRequest;
use Facebook\GraphObject;
use Facebook\FacebookRequestException;

function publishUrlToPage($url, $message = null, $backdated_time = null)
{       
    $client_id = 'xxxxxxx';
    $client_secrets = 'xxxxxxxx';

    $long_live_access_token = "xxxxx";

    // Configures and app ID and secret that will be used by default throughout the SDK (but can be overridden whenever necessary using parameters to other methods.
    FacebookSession::setDefaultApplication($client_id, $client_secrets);

    // You can also create a FacebookSession with an access token you've acquired through some other means, by passing it to the constructor.
    $session = new FacebookSession($long_live_access_token);

    // To validate the session:
    try
    {
        $session->validate();
    }
    catch (FacebookRequestException $ex)
    {
        // Session not valid, Graph API returned an exception with the reason.
        throw $ex;
    }
    catch (\Exception $ex)
    {
        // Graph API returned info, but it may mismatch the current app or have expired.
        throw $ex;
    }

    /*
     * ####################### POST #######################
     */

    $array = array(
        'link' => $url
    );

    // https://developers.facebook.com/docs/graph-api/reference/v2.1/page/feed

    if( ! is_null($message) )
        $array["message"] = $message;

    if( ! is_null($backdated_time) )
        $array["backdated_time"] = $backdated_time->format(DateTime::ISO8601);

    $request = new FacebookRequest($session, 'POST', '/me/feed', $array);

    try
    {
        $response = $request->execute()->getGraphObject();

        return $response->getProperty('id');
    }
    catch(FacebookRequestException $e)
    {
        throw $e;
    }   
}

All the function works properly, with a url or with a url+message.

The backdated_time seems not working.

As a value, I used a ISO 8601 one like this 2014-08-14T00:00:00+00:00, as suggested in this post

When I make a call with this value I get this error:

["statusCode":"Facebook\FacebookRequestException":private]=>
  int(500)
  ["rawResponse":"Facebook\FacebookRequestException":private]=>
  string(87) "{"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1}}"
  ["responseData":"Facebook\FacebookRequestException":private]=>
  array(1) {
    ["error"]=>
    array(3) {
      ["message"]=>
      string(30) "An unknown error has occurred."
      ["type"]=>
      string(14) "OAuthException"
      ["code"]=>
      int(1)
    }
  }

Also tried with different date formats

$array["backdated_time"] = 1408046503;  
$array["backdated_time"] = "2014-08-14T00:00:00";
$array["backdated_time"] = "2014-08-14 00:00:00";

but still doesn't works.

I also tried directly from Graph API Explorer and the date parameter (with the same value) works without problems (see attached image, here for full size)

Facebook Graph API Example

Can it be a problem strictly related to the PHP SDK?


EDIT

After several attempts, I restricted the problem to the following case. Using the parameters link and backdated_time together, the request doesnt' work. With the Graph API Explorer does not work as well.

enter image description here

The good thing is that the problem is not strictly related to the PHP SDK, so I can use the Graph API Explorer directly to discover the problem

The bad thing is that now I have the problem with conjunction of those 2 parameters

Community
  • 1
  • 1
Deviling Master
  • 3,033
  • 5
  • 34
  • 59
  • You could go file a bug report. But I think this might be intentional – because that link you are posting might have shown different content at the time you are trying to backdate it to, but Facebook can only scrape that link at the time you are making the request – so what your post would show might not reflect “reality”. (But if that was the case, they should mention this in the docs – so filing a bug report is a good idea anyway.) – CBroe Aug 16 '14 at 15:02
  • Your thought make sense, but it is really the case, I'm expecting a more verbose error from the output, as happens with other errors. 'Unknown error' made me think about a unexpected situation, unmanaged. I already opened a bug report (here is the link, I think it is public https://developers.facebook.com/bugs/1459388467678603) so I'm waiting for a reply from the support – Deviling Master Aug 16 '14 at 18:06

0 Answers0