我一直在试图弄清楚如何从 php 表单向 Facebook 发布内容,但我不断收到错误消息,我不明白:
2500:必须使用活动访问令牌来查询有关当前用户的信息。
我创建了一个应用程序,获取了 appID 和 appSecret,并使用了以下代码:
$config = array(
'appId' => $this->config->Facebook->Api,
'secret' => $this->config->Facebook->Secret,
'cookie' => true
);
$facebook = new Facebook($config);
echo "Facebook: " . print_r($facebook, true) . "<br>";
$token = $facebook->getAccessToken();
$facebook->setAccessToken($token);
echo "Facebook: " . print_r($facebook, true) . "<br>";
$attachment = array(
'message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://mylink.com',
'description' => 'this is a description',
'picture' => 'http://mysite.com/pic.gif'
);
$result = $facebook->api('/me/feed/', 'post', $attachment);
echo "Result: " . print_r($result, true) . "<br>";
我也尝试不使用 setAccessToken,将令牌设置为消息中的参数:
$config = array(
'appId' => $this->config->Facebook->Api,
'secret' => $this->config->Facebook->Secret,
'cookie' => true
);
$facebook = new Facebook($config);
echo "Facebook: " . print_r($facebook, true) . "<br>";
$token = $facebook->getAccessToken();
echo "Token: " . print_r($token, true) . "<br>";
$attachment = array(
'message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://mylink.com',
'description' => 'this is a description',
'picture' => 'http://mysite.com/pic.gif',
'access_token' => $token
);
$result = $facebook->api('/me/feed/', 'post', $attachment);
echo "Result: " . print_r($result, true) . "<br>";
我测试了两种方式,因为我浏览了其他站点的几个 stackoverflow 帖子和其他资源,但是这些都不起作用,因为我不断收到以下错误:
2500:必须使用活动访问令牌来查询有关当前用户的信息。