繁体   English   中英

使用 PHP 中的 oAuth 从 Twitter 中的家庭时间线访问推文?

[英]Accessing tweets from home timeline in Twitter using oAuth in PHP?

我正在尝试在用户时间轴中打印第一条推文。

$hometimeline = $twitterObj->get_statusesHome_timeline();
$stream=$hometimeline->responseText;
$user=$stream[0]->user;
$tweet=$user->text;
echo $tweet;

这不会打印任何东西。 我在这里做错了什么?

如果我回$hometimeline->responseText它会显示在屏幕上
[
{"in_reply_to_status_id_str":null, "coordinates":null, "geo":null, "user":{"profile_use_background_image":true,"text":"I am back",....},"id_str": "121212"},

{... 很快} ]

您将收到 json 字符串作为响应。 使用json_decode解析响应,您将能够将其作为数组或 stdobject 进行管理

在与响应交互之前执行此操作

$stream = json_decode( $hometimeline->responseText, true);

编辑

请记住,您始终可以使用print_r进行调试

试试这个:

$hometimeline = $twitterObj->get_statusesHome_timeline();
$stream = json_decode( $hometimeline->responseText );
$user=$stream[0]->user;
$tweet=$user->text;
echo $tweet;

json_decode 将您收到的 JSON 字符串转换为 PHP object。

暂无
暂无

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

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