试图使用facebook-php-sdk库来检索Facebook的帖子 [英] trying to use use facebook-php-sdk library to retrive facebook posts

查看:144
本文介绍了试图使用facebook-php-sdk库来检索Facebook的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Facebook的帖子拉到我的网站上,以便我可以以我自己的格式保存和显示。我正在尝试使用Facebook开发人员页面上的Facebook-php-sdk库。我需要图书馆后,我使用以下代码:

I am trying to pull facebook posts onto my site so that I can save and display it in my own format. I am trying to use the facebook-php-sdk library, found on the Facebook Developer pages. I used the following code after I required the library:

$facebook = new Facebook(array(
'appId'  => 'MY APP ID',
'secret' => 'MY APP SECRET',
));

// Get User ID
$user = $facebook->getUser();
print_r($facebook);
print_r($user);

print_r到$ facebook显示了一个完整的Facebook对象,所以我知道它正在创建。

The print_r into $facebook showed me a full facebook object, so I know its being created properly.

 object(Facebook)#325 (9) { ["sharedSessionID":protected]=> NULL ["appId":protected]=> string(15) "[MYAPPID]" ["appSecret":protected]=> string(32) "[MYAPPSECRET]" ["user":protected]=> int(0) ["signedRequest":protected]=> NULL ["state":protected]=> NULL ["accessToken":protected]=> string(48) "[MYAPPID]|[MYAPPSECRET]" ["fileUploadSupport":protected]=> bool(false) ["trustForwarded":protected]=> bool(false) }

(我从上面的报价中拿出了我的应用程序ID和应用程序密码)。

(I took my app id and app secret codes out of the quote above).

但是,print_r到$ user显示

However, the print_r into $user displayed

int(0).

我在这里缺少什么?

推荐答案

我在这里缺少什么?验证用户。您正在调用 getUser(),但直到您进行身份验证,Facebook不知道哪个用户获取详细信息。我也不确定为什么你错过了,因为它是PHP SDK的GitHub repo的例子。

"What am I missing here?" Authenticating the user. You’re calling getUser(), but until you authenticate, Facebook doesn’t know which user to get details for. I’m also unsure why you’ve missed it, as it’s the example on the GitHub repo for the PHP SDK.

这篇关于试图使用facebook-php-sdk库来检索Facebook的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆