【问题标题】:Unable to Access Key-Value Pair Twitter API User Timeline无法访问键值对 Twitter API 用户时间线
【发布时间】: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


    【解决方案1】:

    它在另一个数组中。试试下面的代码

    echo "Screen Name: " . $a[0]['screen_name'];       
    

    【讨论】:

    • +1 感谢您的回复。我是这么认为的,但是在将其更改为 $a[0]['screen_name']; 后,我仍然收到此 undefined index 错误。我使用的网名是正确的。不知道为什么我仍然收到此错误
    • 非常感谢您为我指明了正确的方向。这行得通! echo "Screen Name: " . $a[0]['user']['screen_name'];
    猜你喜欢
    • 2015-06-06
    • 2015-06-12
    • 2013-12-11
    • 1970-01-01
    • 2019-04-03
    • 1970-01-01
    • 2014-05-04
    • 2021-09-03
    • 2013-03-30
    相关资源
    最近更新 更多