尝试从 codebird API 结果中解析 JSON 时出错
Error trying to parse JSON from a codebird API result
我正在尝试通过 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)
returns Warning: json_decode() expects parameter 1 to be string, object given
任何帮助将不胜感激......
谢谢。干杯
statuses_userTimeline($params)
正在返回对象。按原样使用对象。
我刚刚阅读了文档和一些 Whosebug 问题,发现我需要将数据类型更改为数组并使用它。然后它看起来像:
<?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;
我正在尝试通过 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)
returns Warning: json_decode() expects parameter 1 to be string, object given
任何帮助将不胜感激......
谢谢。干杯
statuses_userTimeline($params)
正在返回对象。按原样使用对象。
我刚刚阅读了文档和一些 Whosebug 问题,发现我需要将数据类型更改为数组并使用它。然后它看起来像:
<?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;