dongliao1860 2013-08-06 15:04
浏览 23
已采纳

无法访问键值对Twitter API用户时间线

I am getting the following undefined index error when I try to access the screen_name key value pair from Twitter API 1.1 User Timeline https://api.twitter.com/1.1/statuses/user_timeline.json

A PHP Error was encountered

Severity: Notice

Message: Undefined index: screen_name

Filename: controllers/search.php

Line Number: 98

I can see the screen_name key when I print_r(); the associative array that stores the results:

Array ( [0] => Array ( [created_at] => Tue Mar 19 21:55:31 +0000 2013 [id] => 3.141330578148E+17 [id_str] => 314133057814798336 [text] => Win a 4-Pack of tickets to the @VanAutoShow March 26-31 via @604Now – http://t.co/2G0pyNNgLl RT to Enter! [source] => Twitter for Mac [truncated] => [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] => Array ( [id] => 128700677 [id_str] => 128700677 [name] => Bernard Poon [screen_name] => StackOverflow [location] => Vancouver, BC [description] => Code Monkey that calls Vancouver home. Loves Apple products and newbie photographer. [url] => http://t.co/wlxhr5tpes [entities] => Array ( [url] => Array ( [urls] => Array ( [0] => Array ( [url] => http://t.co/wlxhr5tpes [expanded_url] => http://ceciliaandbernard.com [display_url] => ceciliaandbernard.com [indices] => Array ( [0] => 0 1 => 22 ) ) ) ) [description] => Array ( [urls] => Array ( ) ) ) [protected] => [followers_count] => 157 [friends_count] => 13 [listed_count] => 4 [created_at] => Thu Apr 01 23:16:57 +0000 2010 [favourites_count] => 0 [utc_offset] =>

I am able to access the screen_name key value pair if I use the Users Show TWitter API 1.1 resource with no errors. However, when I use the User Timeline Twitter API 1.1 resource, I get the above undefined index error. Below is a code snippet of the function I'm using to access both of these resources with different results:

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'];       
}

Any assistance will be greatly appreciated. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douhu7807 2013-08-06 15:06
    关注

    its inside another array. try the following code

    echo "Screen Name: " . $a[0]['screen_name'];       
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化