Facebook stream.publish的先决条件是什么?

Ale*_*Mcp 4 php api facebook

我想知道是否有人会帮我解决我的stream.publish测试问题.我以为我有所有正确的作品.这是代码:

<?php
require_once 'facebook.php';
$appapikey = 'xxxxxxx';
$appsecret = 'xxxxxxx';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();


$message = "Will this status show up and allow me to dominate the world?!";
$uid = $user_id;
echo $uid;
$facebook->api_client->stream_publish($message,$uid);
Run Code Online (Sandbox Code Playgroud)

我期待的是我的状态改为$ message的内容.相反,我的UID是echo'd,然后它会抛出500错误.我允许publish_stream以及 offline_access(在我的应用程序设置中验证,通过我的个人资料),API密钥将这一小段代码挂钩到我的应用程序.我需要做哪些其他部分才能使这个简单的例子有效?我发现FB文档有点难以组合在一起.

- include是官方的PHP Facebook库

Mik*_*inz 6

stream_publish()需要两个以上的参数:

stream_publish($message, $attachment = null, 
               $action_links = null, $target_id = null, 
               $uid = null)
Run Code Online (Sandbox Code Playgroud)

$ target_id是您要发布的用户或页面,$ uid是正在发布的用户或页面 - 默认为您的会话ID.要完全明确这一点,我想你需要尝试

<?php
require_once 'facebook.php';
$appapikey = 'xxxxxxx';
$appsecret = 'xxxxxxx';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();

$message = "Will this status show up and allow me to dominate the world?!";

echo $user_id;
$facebook->api_client->stream_publish($message,null,null,$user_id,$user_id);
Run Code Online (Sandbox Code Playgroud)

另一种形式可能是:

$app_id = 'xxxxxxx'; 
$facebook->api_client->stream_publish($message,null,null,$user_id,$app_id);
Run Code Online (Sandbox Code Playgroud)