简体   繁体   English

Facebook 和 php - 如何将内容从我的网站发布到我的 facebook 墙上?

[英]Facebook and php - how to post content from my site to my facebook wall?

I'm very confused with this facebook api.我对这个 facebook api 很困惑。

I've facebook username and password in my database, I want to sign and post content from my site to my facebook wall.我的数据库中有 facebook 用户名和密码,我想在我的网站上签名并将内容发布到我的 facebook 墙上。 how do I do it?我该怎么做?

I've downloaded the facebook-php-sdk, just need to be able to include the "post" part in my php file to make things happen, I've this code at the moment我已经下载了 facebook-php-sdk,只需要能够在我的 php 文件中包含“发布”部分就可以了,我现在有这个代码

require_once ('facebook.php');
                $app_id = "MY_ID";
                $app_secret = "MY_SECRET";
                $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));

                if(is_null($facebook->getUser())) {

                    header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
                    exit;
                } 

                $status = $facebook->api('/me/feed', 'POST', array('message' => utf8_encode($my_message)));

with this I just get a internal server error, nothing more to have an idea of what I'm doing wrong...有了这个我只是得到一个内部服务器错误,没有更多的想法我做错了什么......

even with var_dump($status) I get nothing Thanks即使使用 var_dump($status) 我什么也得不到 谢谢

You cannot log in as a user on the Facebook Graph API.您无法在 Facebook 图表 API 上以用户身份登录。 You should never be asking for any user's Facebook password in the first place, which is why Facebook do not allow this.首先,您永远不应该询问任何用户的 Facebook 密码,这就是 Facebook 不允许这样做的原因。

The API allows you to log in as an 'app', which can be granted permissions by Facebook users. API 允许您作为“应用程序”登录,Facebook 用户可以授予该权限。 You will need to create a Facebook app at https://www.facebook.com/developers/apps.php . You will need to create a Facebook app at https://www.facebook.com/developers/apps.php .

Once this is done, you can prompt a user to post on their wall or use the Graph API using http://developers.facebook.com/docs/reference/dialogs/feed/完成此操作后,您可以提示用户在他们的墙上发帖或使用图表 API 使用http://developers.facebook.com/docs/reference/dia

Firstly try (i hope you entered your $app_id and $app_secret):首先尝试(我希望你输入了你的 $app_id 和 $app_secret):

require_once ('facebook.php');
$app_id = "MY_ID";
$app_secret = "MY_SECRET";
$facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
$user = $facebook->getUser();

var_export($user);

You should se data if you're logged in properly.如果您正确登录,您应该查看数据。

Than you should maybe look at this page for an example Facebook Graph API PHP SDK posting on page as page比您应该查看此页面的示例Facebook 图表 API PHP ZF20E3C5E54C0AB3DF6AZ5D6 页面上的页面 BF86

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM