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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1154742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 01:16:07  来源:igfitidea点击:

What are the prerequisites for Facebook stream.publish?

phpapifacebook

提问by Alex Mcp

I'm wondering if someone would help me troubleshoot my test for stream.publish. I thought I had all the right pieces. Here's the code:

我想知道是否有人会帮助我对 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);

What I'm expecting is my status to change to $message's content. What happens instead is that my UID is echo'd, and then it throws a 500 error. I've allowed publish_streamas well as offline_access(verified in my app settings, via my profile), the the API key hooks this small bit of code to my app. What other pieces do I need to make this simple example work? I'm finding the FB documentation a little hard to put together.

我期待的是我的状态更改为 $message 的内容。相反,我的 UID 被回显了,然后它抛出了 500 错误。我允许publish_stream,以及 offline_access(在我的应用程序设置验证,通过我的个人资料),该API密钥挂钩代码这个小位我的应用程序。我还需要哪些其他部分才能使这个简单的示例工作?我发现 FB 文档有点难以整合。

-- The include is the official PHP Facebook library

-- include 是官方的 PHP Facebook 库

回答by Mike Heinz

stream_publish() takes more than two arguments:

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

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

Where $target_id is the user or page you're publishing toand $uid is the user or page who is doing the publishing - and which defaults to your session id. To be completely explicit about this, I think you need to try

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

An alternate form might be:

另一种形式可能是:

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

回答by Relaxing In Cyprus

This one works in 2011! I had the same problem. Most of the tuts seem to be out of date thanks to Facebook changes. I eventually found a way that worked and did a quick blog article about it here:

这个在 2011 年有效!我有同样的问题。由于 Facebook 的变化,大多数 tuts 似乎已经过时了。我最终找到了一种有效的方法,并在这里写了一篇关于它的快速博客文章:

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

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

There's also a screen shot to show you what the result is. Make sure you also see the blog post about authentication though.

还有一个屏幕截图向您展示结果。不过,请确保您还看到了有关身份验证的博客文章。

回答by Stepan Mazurov

Remove the $uidvariable as it is not needed for publishing. Refer to this wiki entryfor more info

删除$uid变量,因为发布不需要它。有关更多信息,请参阅此wiki 条目

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

回答by Michael

If you are trying to use streamPublish with an iFrame application, here is an awesome step-by-step tutorial that doesn't have to use getAppPermissions:

如果您尝试将 streamPublish 与 iFrame 应用程序一起使用,这里有一个很棒的分步教程,它不必使用 getAppPermissions:

http://thetechnicalexperience.blogspot.com/2010/02/how-to-use-fbconnectstreampublish.html

http://thetechnicalexperience.blogspot.com/2010/02/how-to-use-fbconnectstreampublish.html