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

Creating user-owned Open Graph objects with Facebook's PHP SDK v4

有人试过创建 user-owned Facebook Open Graph objects using 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) The parameter object is required

我也试过这个请求:

$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:

Cannot specify type in both the path and query parameter

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

$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) The parameter object is required

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

我认为您需要像这样 JSON 对 object 参数进行编码:

$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();