Facebook PHP SDK 4.0 - 使用backdated_time向页面发布到Wall时发生OAuthException

时间:2014-08-14 09:01:39

标签: php facebook facebook-graph-api facebook-php-sdk facebook-sdk-4.0

Facebook PHP API Tutorial之后,我写了一个函数,发布了一个指向我的Facebook页面的链接。

this page我得到了如何生成页面访问令牌

正如您从feed page description所看到的,有一个backdated_time参数(仅适用于网页帖子,不适用于用户帖子),可让您选择过去的时间来过帐帖子的日期

这是我职能的主体:

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;
    }   
}

所有功能都正常工作,带有网址或网址+消息。

backdated_time似乎无效。

作为一个值,我按照this post

中的建议使用了ISO {8}这样的{8}

当我使用此值进行调用时,我收到此错误:

2014-08-14T00:00:00+00:00

还尝试使用不同的日期格式

["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)
    }
  }

但仍然无效。

我也直接从Graph API Explorer尝试并且日期参数(具有相同的值)可以正常工作(参见附图,here完整尺寸)

Facebook Graph API Example

这可能是与PHP SDK严格相关的问题吗?


修改

经过多次尝试,我将问题限制在以下情况。同时使用参数$array["backdated_time"] = 1408046503; $array["backdated_time"] = "2014-08-14T00:00:00"; $array["backdated_time"] = "2014-08-14 00:00:00"; link,请求并非如此。工作。使用Graph API Explorer也无法正常工作。

enter image description here

好处是问题与PHP SDK没有严格关系,所以我可以直接使用Graph API Explorer来发现问题

糟糕的是,现在我遇到了这两个参数的结合问题

0 个答案:

没有答案