【问题标题】:Creating user-owned Open Graph objects with Facebook's PHP SDK v4使用 Facebook 的 PHP SDK v4 创建用户拥有的 Open Graph 对象
【发布时间】:2015-01-27 23:47:06
【问题描述】:

有没有人尝试使用v4.0.* of their PHP SDK 创建user-owned Facebook Open Graph objects?我无法在线找到最新的 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 实际发出这个请求。提前感谢您的帮助!

【问题讨论】:

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


    【解决方案1】:

    我相信您需要像这样对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();
    

    【讨论】:

    • 说的有道理,不知道为什么我没想到。看起来它有效,但我实际上无法完成请求,因为我使用的是没有 publish_actions 权限的测试用户令牌
    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 2012-02-11
    • 2015-01-20
    • 2013-10-21
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多