我试图通过codebird-php获取某个人的推文 这是我的代码:
<?php
require_once('src/codebird.php');
\Codebird\Codebird::setConsumerKey('Consumer Key', 'Consumer Secret');
$cb = \Codebird\Codebird::getInstance();
$cb->setToken('Oauth Key', 'Oauth Secret');
$params = array(
'screen_name' => 'WWE',
'count' => 2
);
$reply = $cb->statuses_userTimeline($params);
json_decode($reply);
$main = $reply[0]->text;
echo '<pre>';
var_dump($reply);
echo '</pre>';
var_dump($reply)
的部分输出是
object(stdClass)#35 (4) {
[0]=>
object(stdClass)#2 (23) {
["created_at"]=>
string(30) "Mon Jan 26 08:30:10 +0000 2015"
["id"]=>
float(5.5962935475884E+17)
["id_str"]=>
string(18) "559629354758844416"
["text"]=>
string(112) "RT @WWENXT: .@WWERomanReigns has just made history by becoming the FIRST #WWENXT alumnus to win the #RoyalRumble"
["source"]=>
string(63) "Hootsuite"
["truncated"]=>
bool(false)
["in_reply_to_status_id"]=>
NULL
..........
但json_decode($reply)
返回Warning: json_decode() expects parameter 1 to be string, object given
任何帮助都会得到很多赞赏......
谢谢。干杯
答案 0 :(得分:0)
statuses_userTimeline($params)
正在返回该对象。按原样使用对象。
答案 1 :(得分:0)
我刚刚阅读了文档以及一些Stackoverflow问题并发现我需要将数据类型更改为数组并使用它。然后它看起来像:
<?php
require_once('src/codebird.php');
\Codebird\Codebird::setConsumerKey('Consumer Key', 'Consumer Secret');
$cb = \Codebird\Codebird::getInstance();
$cb->setToken('Oauth Key', 'Oauth Secret');
$params = array(
'screen_name' => 'WWE',
'count' => 2
);
$reply = $cb->statuses_userTimeline($params);
$dat = $data[0];
echo $data[0]->text;