【发布时间】:2013-08-07 16:13:58
【问题描述】:
当我尝试从 Twitter API 1.1 用户时间线 https://api.twitter.com/1.1/statuses/user_timeline.json 访问 screen_name 键值对时,我收到以下 undefined index 错误
遇到了 PHP 错误
严重性:通知
消息:未定义索引:screen_name
文件名:controllers/search.php
行号:98
当我 print_r(); 时我可以看到 screen_name 键存储结果的关联数组:
数组 ( [0] => 数组 ( [created_at] => 2013 年 3 月 19 日星期二 21:55:31 +0000 [id] => 3.141330578148E+17 [id_str] => 314133057814798336 [文本] => 通过@604Now 赢得 3 月 26 日至 31 日@VanAutoShow 的 4 张门票 – http://t.co/2G0pyNNgLlRT 进入! [来源] => Mac 版 Twitter [截断] => [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => [in_reply_to_screen_name] => [user] => 数组([id] => 128700677 [id_str] => 128700677 [name] => Bernard Poon [screen_name] => StackOverflow [location] => Vancouver, BC [description] => Code Monkey 称温哥华为家。喜欢苹果产品和新手 摄影师。 [url] => http://t.co/wlxhr5tpes [entities] => 数组 ( [url] => 数组 ( [urls] => 数组 ( [0] => 数组 ( [url] => http://t.co/wlxhr5tpes [expanded_url] => http://ceciliaandbernard.com [display_url] => ceciliaandbernard.com [indices] => 数组 ( [0] => 0 1 => 22 ) ) ) ) [描述] => 数组 ([urls] => 数组 ())) [受保护] => [followers_count] => 157 [friends_count] => 13 [listed_count] => 4 [created_at] => 2010 年 4 月 1 日星期四 23:16:57 +0000 [favourites_count] => 0 [utc_offset] =>
如果我使用 Users Show TWitter API 1.1 资源且没有错误,我可以访问 screen_name 键值对。但是,当我使用 User Timeline Twitter API 1.1 资源时,我收到上述 undefined index 错误。下面是我用来访问这两种资源的函数的代码 sn-p,结果不同:
function does_user_exist($r)
{
// convert to associative array
// inorder to search for keys
$a = json_decode($r, true);
echo "Screen Name: " . $a['screen_name'];
}
任何帮助将不胜感激。提前致谢。
【问题讨论】:
标签: php codeigniter twitter