2009-07-20 196 views
4

我想知道是否有人会帮我排查我的stream.publish测试。我以为我拥有所有正确的作品。这里是代码: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); 

我期待的是我的状态改变为$ message的内容。反而会发生什么,我的UID被echo'd,然后它会引发500错误。我允许publish_stream以及offline_access(通过我的个人资料在我的应用设置中验证),API密钥将这一小部分代码挂钩到我的应用。做这个简单的例子还需要做些什么?我发现FB文档有点难以放在一起。

- 的包括是官方的PHP Facebook的库

回答

6

stream_publish()的时间超过两个参数:

stream_publish($message, $attachment = null, 
       $action_links = null, $target_id = null, 
       $uid = null) 

其中$ 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); 

另一种形式可能是:

$app_id = 'xxxxxxx'; 
$facebook->api_client->stream_publish($message,null,null,$user_id,$app_id); 
+0

我的问题是所有的参数都被列为可选参数,所以我只包含了我认为我需要的东西,而没有想到它们的顺序决定了它们的意思(IE,使用占位符来回答所有可用的参数)非常感谢为了帮助我。 – 2009-07-22 01:08:45

0

取出$uid变量并不需要发布它。请参阅本wiki entry更多信息

$stream_post_id = $facebook->api_client->stream_publish($message); 
//returns $post_id to use if you want to revert the creation. 
+0

在我的脚本中,它将如何知道要发布消息的用户帐户? – 2009-07-21 15:47:48

+0

这样的电话号码 $ facebook-> api_client-> stream_publish($ message,$ attachment,$ actionlinks); 它会发布到你所有的朋友墙上。 – 2009-09-02 09:23:14

2

这一个工程!我有同样的问题。由于Facebook的变化,大部分内容似乎已经过时。我终于找到一种方式,在这里工作,快速做了博客文章吧:

http://facebookanswers.co.uk/?p=214

还有一个屏幕截图给你看的结果是什么。确保你也看到有关身份验证的博客文章。