使用Facebook的PHP SDK v4创建用户拥有的Open Graph对象

时间:2015-01-27 23:47:07

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

是否有人尝试使用user-owned Facebook Open Graph objects创建v4.0.* of their PHP SDK?我无法在线找到任何最新Open Graph PHP请求的工作示例。

目前,我的请求是这样的:

$graphObject = (
    new FacebookRequest(
        $this->facebookSession, 
        'POST', 
        "/me/objects/{$objectType}", [
            'title' => $title,
            'image' => $image,
            'url' => $url,
            'description' => $description,
            'site_name' => $this->siteName
        ]
    )
)->execute()->getGraphObject();

抛出FacebookAuthorizationException

  

(#100)参数对象是必需的

我也尝试过这个请求:

$graphObject = (
    new FacebookRequest(
        $this->facebookSession, 
        'POST', 
        "/me/objects/{$objectType}", [
            'title' => $title,
            'image' => $image,
            'url' => $url,
            'description' => $description,
            'type' => $objectType,
            'site_name' => $this->siteName
        ]
    )
)->execute()->getGraphObject();

抛出FacebookAuthorizationException

  

无法在路径和查询参数中指定类型

最后,我尝试过这个请求:

$graphObject = (
    new FacebookRequest(
        $this->facebookSession, 
        'POST', 
        "/me/objects/", [
            'title' => $title,
            'image' => $image,
            'url' => $url,
            'description' => $description,
            'type' => $objectType,
            'site_name' => $this->siteName
        ]
    )
)->execute()->getGraphObject();

抛出FacebookAuthorizationException

  

(#100)参数对象是必需的

在我上面链接的创建Open Graph对象的文档中,我看到了正确的cURL请求是什么,我只是对如何使用PHP SDK实际发出这个请求感到有点迷失。在此先感谢您的帮助!

1 个答案:

答案 0 :(得分:5)

我相信您需要对object参数进行JSON编码,如下所示:

$graphObject = (
    new FacebookRequest(
        $this->facebookSession, 
        'POST', 
        "/me/objects/{$objectType}",
        [
          'object' => json_encode([
            'title' => $title,
            'image' => $image,
            'url' => $url,
            'description' => $description,
            'site_name' => $this->siteName
          ])
        ]
    )
)->execute()->getGraphObject();