ale*_*ung 2 php facebook facebook-graph-api facebook-php-sdk
有没有人尝试使用他们的PHP SDK的v4.0.*创建用户拥有的Facebook Open Graph对象?我无法在线找到任何最新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();
Run Code Online (Sandbox Code Playgroud)
哪一个抛出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();
Run Code Online (Sandbox Code Playgroud)
哪一个抛出FacebookAuthorizationException:
无法在path和query参数中指定类型
最后,我尝试过这个请求:
$graphObject = (
new FacebookRequest(
$this->facebookSession,
'POST',
"/me/objects/", [
'title' => $title,
'image' => $image,
'url' => $url,
'description' => $description,
'type' => $objectType,
'site_name' => $this->siteName
]
)
)->execute()->getGraphObject();
Run Code Online (Sandbox Code Playgroud)
哪一个抛出FacebookAuthorizationException:
(#100)参数对象是必需的
在我上面链接的用于创建Open Graph对象的文档中,我看到了正确的cURL请求是什么,我只是对如何使用PHP SDK实际发出此请求感到有点迷失.在此先感谢您的帮助!
小智 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();
Run Code Online (Sandbox Code Playgroud)