gpt4 book ai didi

php - 从 Facebook API 获取随机用户的公开帖子

转载 作者:行者123 更新时间:2023-11-30 05:28:58 25 4
gpt4 key购买 nike

我想获取一些随机用户的最新帖子(诅咒的公开帖子)。我想因为它们是公开帖子,所以我不需要征求所有者的许可。这是我的代码:

function fetchUrl($url){
return file_get_contents($url);
}

$profile_id = "4";

$app_id = "****";
$app_secret = "****";

$authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={$app_id}&client_secret={$app_secret}");

$json_object = fetchUrl("https://graph.facebook.com/{$profile_id}/posts?{$authToken}");
$feedarray = json_decode($json_object , true );

foreach ( $feedarray as $feed_data )
{
var_dump( $feed_data);
}

它返回一些关于用户事件的数据,但没有关于帖子的数据!

这是例子

这是我的fb acc(我很少使用它),我刚刚发了一个帖子(test3) https://www.facebook.com/Hereticcc

当我使用我的帐户 ID 运行此代码时

$json_object = fetchUrl("https://graph.facebook.com/{$profile_id}/posts?{$authToken}&limit=50");
$feedarray = json_decode($json_object , true );
foreach ( $feedarray['data'] as $k=>$v )
{
/// var_dump( $v['story']);
echo $v['story']; echo '<br />';
}

这就是我得到的!没有我刚刚加的帖子的迹象只有喜欢和友谊

Mj Tb Z likes Facebook Developers.
Mj Tb Z and Ahmad Masajedi are now friends.
Mj Tb Z and Di M AH are now friends.
Mj Tb Z likes Cult of Luna.
Mj Tb Z likes a link.
Mj Tb Z likes a status.
Mj Tb Z likes a link.
Mj Tb Z and Eh San Mans are now friends.
Mj Tb Z likes a link.
Mj Tb Z likes Mist Within.
Mj Tb Z likes Filmhaa.
Mj Tb Z likes a link.
Mj Tb Z and Mamad RJ are now friends.
Mj Tb Z likes a link.
Mj Tb Z is now using Facebook in English (US).
Mj Tb Z is now friends with Mushu Khoshbakht and Samin Zavarkesh.
Mj Tb Z likes a photo.
Mj Tb Z updated his cover photo.
Mj Tb Z and Mohammad Khoshbakht are now friends.

我试过FQL

这是我的代码

$authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={$app_id}&client_secret={$app_secret}");

echo $fql_query_url = 'https://graph.facebook.com/'
. 'fql?q=SELECT+message+FROM+stream+WHERE+source_id=4'
. '&' . $authToken;

echo '<br />';
$fql_query_result = fetchUrl($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);

echo '<pre>';
print_r("query results:");
print_r($fql_query_obj);
echo '</pre>';

结果如下:

https://graph.facebook.com/fql?q=SELECT+message+FROM+stream+WHERE+source_id=4&access_token=284654551659478|D7T6A1uMSr1Qm1LLFBB9CQk_vK8

query results:Array
(
[data] => Array
(
)

)

最佳答案

未经他/她的许可,您不能阅读随机用户的帖子提要(包括公开的状态更新)。您需要一个有效的 User Access Token来自具有 read_stream 权限的用户以执行此操作。

使用有效的访问 token ,您可以通过在 stream 上使用 FQL 查询为特定用户或他/她的 friend 实现此目的 table 。您可以使用如下查询:

SELECT post_id, message FROM stream WHERE source_id = {User_ID} LIMIT 50 

或者,如果您特别关心用户或他/她的 friend 的状态,您可以使用 status表格如下:

SELECT status_id, message FROM status WHERE uid = {User_ID} LIMIT 50

但是,有一种方法可以读取发布到 Facebook 的用户状态更新和页面状态更新流。这可以通过使用 Public Feed API 来完成。 .但这只会包括将隐私设置为“公开”的状态更新包含在流中。此外,您目前无法申请使用该 API,因为它的访问权限受到限制。

关于php - 从 Facebook API 获取随机用户的公开帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21010928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com