gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:52:53 24 4
gpt4 key购买 nike

有人尝试过创建 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) 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 实际发出此请求有点迷失。预先感谢您的帮助!

最佳答案

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

关于php - 使用 Facebook 的 PHP SDK v4 创建用户拥有的 Open Graph 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28182183/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com