2012-12-08 3 views
1

좋아, 그래서 내 친구의 상태를 반환하는 Twitter API 호출을 만들었습니다, var_dump 않았다 및 정보 배열을 반환했습니다. 그러나, 나는 단지 내 친구의 프로필 이미지를 잡을 싶습니다. . 그래서 내가 그것을 잡으려고했고, 그것은 아무것도 반환하지 않습니다 무엇이 배열의 내용을 twitter API에서 어떻게 출력 할 수 있습니까?

아래의 루프 아래 .. 내 친구의 이미지를 표시하도록되어 루프를 위해서 var_dump 나에게 반환 무엇의 샘플이
$friends = $connection->get('statuses/friends_timeline'); //method that catches my friends'statuses on Twitter. 
var_dump($friends); 

입니다 .. 내가 어디가 잘못 될까 ???

if(is_array($friends)) 
{ 
    shuffle($friends); 
}    

for($i=0; $i <=count($friends);$i++) 
    if (is_array($friends)) 
    { 
     foreach ($friends[$i] as $key => $value) 
     {          
      if(array_key_exists("profile_image_url", $friends[$i])) 
      {         
       echo "<img src='". $value."' width='100' height='100'/>"; 
      } 

     } 
    } 

array(20) { 
    [0]=> 
    object(stdClass)#7 (19) { 
    ["id_str"]=> 
    string(18) "277310503989149697" 
    ["user"]=> 
    object(stdClass)#8 (37) { 
     ["id"]=> 
     int(48948037) 
     ["default_profile"]=> 
     bool(false) 
     ["following"]=> 
     bool(false) 
     ["profile_background_tile"]=> 
     bool(true) 
     ["id_str"]=> 
     string(8) "48948037" 
     ["url"]=> 
     NULL 
     ["profile_sidebar_fill_color"]=> 
     string(6) "CCD7DB" 
     ["profile_image_url"]=> 
     string(66) "http://a0.twimg.com/profile_images/1821098433/photo__1__normal.JPG" 
     ["utc_offset"]=> 
     int(-28800) 
     ["contributors_enabled"]=> 
     bool(false) 
     ["time_zone"]=> 
     string(26) "Pacific Time (US & Canada)" 
     ["name"]=> 
     string(16) "Semirindi Makala" 
     ["listed_count"]=> 
     int(1) 
     ["profile_background_color"]=> 
     string(3) "fff" 
     ["screen_name"]=> 
     string(7) "MASE_85" 
     ["geo_enabled"]=> 
     bool(false) 
     ["protected"]=> 
     bool(false) 
     ["follow_request_sent"]=> 
     bool(false) 
     ["location"]=> 
     string(13) "Teh internets" 
     ["profile_background_image_url"]=> 
     string(69) "http://a0.twimg.com/profile_background_images/422730827/photo__1_.JPG" 
     ["friends_count"]=> 
     int(15) 
     ["verified"]=> 
     bool(false) 
     ["profile_link_color"]=> 
     string(6) "0084B4" 
     ["statuses_count"]=> 
     int(59) 
     ["notifications"]=> 
     bool(false) 
     ["default_profile_image"]=> 
     bool(false) 
     ["favourites_count"]=> 
     int(0) 
     ["lang"]=> 
     string(2) "en" 
     ["profile_background_image_url_https"]=> 
     string(71) "https://si0.twimg.com/profile_background_images/422730827/photo__1_.JPG" 
     ["profile_use_background_image"]=> 
     bool(true) 
     ["profile_image_url_https"]=> 
     string(68) "https://si0.twimg.com/profile_images/1821098433/photo__1__normal.JPG" 
     ["profile_text_color"]=> 
     string(6) "333333" 
     ["followers_count"]=> 
     int(9) 
     ["profile_sidebar_border_color"]=> 
     string(6) "A8C7F7" 
     ["is_translator"]=> 
     bool(false) 
     ["description"]=> 
     string(0) "" 
     ["created_at"]=> 
     string(30) "Sat Jun 20 06:50:28 +0000 2009" 
    } 
    ["in_reply_to_user_id"]=> 
    NULL 
    ["in_reply_to_status_id"]=> 
    NULL 
    ["coordinates"]=> 
    NULL 
    ["geo"]=> 
    NULL 
    ["created_at"]=> 
    string(30) "Sat Dec 08 07:15:50 +0000 2012" 

    ["retweet_count"]=> 
    int(0) 
    ["favorited"]=> 
    bool(false) 
    ["created_at"]=> 
    string(30) "Sat Dec 08 06:40:59 +0000 2012" 
    ["truncated"]=> 
    bool(false) 
    ["in_reply_to_screen_name"]=> 
    NULL 
    ["retweeted"]=> 
    bool(false) 
    ["text"]=> 
    string(29) "Sat, 08 Dec 12 06:40:59 +0000" 
    ["place"]=> 
    NULL 
    ["source"]=> 
    string(65) "<a href="http://www.europe-zone.com" rel="nofollow">Madscore1</a>" 
    ["in_reply_to_status_id_str"]=> 
    NULL 
    ["id_str"]=> 
    string(18) "277301732894179328" 
    ["in_reply_to_user_id"]=> 
    NULL 
    ["in_reply_to_status_id"]=> 
    NULL 
    ["id"]=> 
    float(2.7730173289418E+17) 
    } 
    [7]=> 
    object(stdClass)#21 (19) { 
    ["in_reply_to_status_id_str"]=> 
    NULL 
    ["user"]=> 
    object(stdClass)#22 (37) { 
     ["id"]=> 
     int(48948037) 
     ["followers_count"]=> 
     int(9) 
     ["following"]=> 
     bool(false) 
     ["url"]=> 
     NULL 
     ["profile_sidebar_border_color"]=> 
     string(6) "A8C7F7" 
     ["profile_image_url_https"]=> 
     string(68) "https://si0.twimg.com/profile_images/1821098433/photo__1__normal.JPG" 
     ["utc_offset"]=> 
     int(-28800) 
     ["default_profile"]=> 
     bool(false) 
     ["profile_background_tile"]=> 
     bool(true) 
     ["name"]=> 
     string(16) "Semirindi Makala" 
     ["id_str"]=> 
     string(8) "48948037" 
     ["profile_sidebar_fill_color"]=> 
     string(6) "CCD7DB" 
     ["screen_name"]=> 
     string(7) "MASE_85" 
     ["protected"]=> 
     bool(false) 
     ["profile_image_url"]=> 
     string(66) "http://a0.twimg.com/profile_images/1821098433/photo__1__normal.JPG" 
     ["location"]=> 
     string(13) "Teh internets" 
     ["contributors_enabled"]=> 
     bool(false) 
     ["listed_count"]=> 
     int(1) 
     ["time_zone"]=> 
     string(26) "Pacific Time (US & Canada)" 
     ["profile_background_color"]=> 
     string(3) "fff" 
     ["geo_enabled"]=> 
     bool(false) 
     ["notifications"]=> 
     bool(false) 
     ["follow_request_sent"]=> 
     bool(false) 
     ["lang"]=> 
     string(2) "en" 
     ["profile_background_image_url"]=> 
     string(69) "http://a0.twimg.com/profile_background_images/422730827/photo__1_.JPG" 
     ["friends_count"]=> 
     int(15) 
     ["statuses_count"]=> 
     int(56) 
     ["verified"]=> 
     bool(false) 
     ["profile_link_color"]=> 
     string(6) "0084B4" 
     ["default_profile_image"]=> 
     bool(false) 
     ["favourites_count"]=> 
     int(0) 
     ["profile_background_image_url_https"]=> 
     string(71) "https://si0.twimg.com/profile_background_images/422730827/photo__1_.JPG" 
     ["profile_use_background_image"]=> 
     bool(true) 
     ["is_translator"]=> 
     bool(false) 
     ["description"]=> 
     string(0) "" 
     ["profile_text_color"]=> 
     string(6) "333333" 
     ["created_at"]=> 
     string(30) "Sat Jun 20 06:50:28 +0000 2009" 
    } 
    ["contributors"]=> 
    NULL 
    ["coordinates"]=> 
    NULL 
    ["geo"]=> 
    NULL 
    ["retweet_count"]=> 
    int(0) 
    ["favorited"]=> 
    bool(false) 
    ["created_at"]=> 
    string(30) "Sat Dec 08 06:28:19 +0000 2012" 
    ["in_reply_to_user_id_str"]=> 
    NULL 
    ["truncated"]=> 
    bool(false) 
    ["in_reply_to_screen_name"]=> 
    NULL 
    ["retweeted"]=> 
    bool(false) 
    ["text"]=> 
    string(29) "Sat, 08 Dec 12 06:28:18 +0000" 
    ["place"]=> 
    NULL 
    ["source"]=> 
    string(65) "<a href="http://www.europe-zone.com" rel="nofollow">Madscore1</a>" 
    ["id_str"]=> 
    string(18) "277298543398617088" 
    ["in_reply_to_user_id"]=> 
    NULL 
    ["in_reply_to_status_id"]=> 
    NULL 
    ["id"]=> 
    float(2.7729854339862E+17) 
    } 
    [8]=> 
    object(stdClass)#23 (19) { 
    ["user"]=> 
    object(stdClass)#24 (37) { 
     ["id"]=> 
     int(48948037) 
     ["default_profile_image"]=> 
     bool(false) 
     ["followers_count"]=> 
     int(9) 
     ["following"]=> 
     bool(false) 
     ["url"]=> 
     NULL 
     ["favourites_count"]=> 
     int(0) 
     ["profile_background_image_url_https"]=> 
     string(71) "https://si0.twimg.com/profile_background_images/422730827/photo__1_.JPG" 
     ["profile_sidebar_border_color"]=> 
     string(6) "A8C7F7" 
     ["utc_offset"]=> 
     int(-28800) 
     ["profile_background_tile"]=> 
     bool(true) 
     ["name"]=> 
     string(16) "Semirindi Makala" 
     ["id_str"]=> 
     string(8) "48948037" 
     ["is_translator"]=> 
     bool(false) 
     ["profile_sidebar_fill_color"]=> 
     string(6) "CCD7DB" 
     ["screen_name"]=> 
     string(7) "MASE_85" 
     ["protected"]=> 
     bool(false) 
     ["profile_image_url"]=> 
     string(66) "http://a0.twimg.com/profile_images/1821098433/photo__1__normal.JPG" 
     ["location"]=> 
     string(13) "Teh internets" 
     ["contributors_enabled"]=> 
     bool(false) 
     ["default_profile"]=> 
     bool(false) 
     ["time_zone"]=> 
     string(26) "Pacific Time (US & Canada)" 
     ["profile_image_url_https"]=> 
     string(68) "https://si0.twimg.com/profile_images/1821098433/photo__1__normal.JPG" 
     ["profile_background_color"]=> 
     string(3) "fff" 
     ["geo_enabled"]=> 
     bool(false) 
     ["notifications"]=> 
     bool(false) 
     ["follow_request_sent"]=> 
     bool(false) 
     ["listed_count"]=> 
     int(1) 
     ["lang"]=> 
     string(2) "en" 
     ["profile_background_image_url"]=> 
     string(69) "http://a0.twimg.com/profile_background_images/422730827/photo__1_.JPG" 
     ["verified"]=> 
     bool(false) 
     ["profile_link_color"]=> 
     string(6) "0084B4" 
     ["profile_use_background_image"]=> 
     bool(true) 
     ["friends_count"]=> 
     int(15) 
     ["description"]=> 
     string(0) "" 
     ["statuses_count"]=> 
     int(51) 
     ["profile_text_color"]=> 
     string(6) "333333" 
     ["created_at"]=> 
     string(30) "Sat Jun 20 06:50:28 +0000 2009" 
    } 
    ["contributors"]=> 
    NULL 
    ["coordinates"]=> 
    NULL 
    ["geo"]=> 
    NULL 
    ["retweet_count"]=> 
    int(0) 
    ["favorited"]=> 
    bool(false) 
    ["created_at"]=> 
    string(30) "Sat Dec 08 06:27:07 +0000 2012" 
    ["truncated"]=> 
    bool(false) 
    ["in_reply_to_screen_name"]=> 
    NULL 
    ["in_reply_to_status_id_str"]=> 
    NULL 
    ["in_reply_to_user_id_str"]=> 
    NULL 
    ["retweeted"]=> 
    bool(false) 
    ["text"]=> 
    string(29) "Sat, 08 Dec 12 06:27:07 +0000" 
    ["place"]=> 
    NULL 
    ["source"]=> 
    string(65) "<a href="http://www.europe-zone.com" rel="nofollow">Madscore1</a>" 
    ["id_str"]=> 
    string(18) "277298243392643072" 
    ["in_reply_to_user_id"]=> 
    NULL 
    ["in_reply_to_status_id"]=> 
    NULL 
    ["id"]=> 
    float(2.7729824339264E+17) 
    } 
    [9]=> 
    object(stdClass)#25 (19) { 
    ["user"]=> 
    object(stdClass)#26 (37) { 
     ["id"]=> 
     int(48948037) 
     ["followers_count"]=> 
     int(9) 
     ["profile_image_url_https"]=> 
     string(68) "https://si0.twimg.com/profile_images/1821098433/photo__1__normal.JPG" 
     ["following"]=> 
     bool(false) 
     ["url"]=> 
     NULL 
     ["profile_sidebar_border_color"]=> 
     string(6) "A8C7F7" 
     ["utc_offset"]=> 
     int(-28800) 
     ["default_profile"]=> 
     bool(false) 
     ["profile_background_tile"]=> 
     bool(true) 
     ["name"]=> 
     string(16) "Semirindi Makala" 
     ["id_str"]=> 
     string(8) "48948037" 
     ["profile_sidebar_fill_color"]=> 
     string(6) "CCD7DB" 
     ["screen_name"]=> 
     string(7) "MASE_85" 
     ["protected"]=> 
     bool(false) 
     ["profile_image_url"]=> 
     string(66) "http://a0.twimg.com/profile_images/1821098433/photo__1__normal.JPG" 
     ["location"]=> 
     string(13) "Teh internets" 
     ["contributors_enabled"]=> 
     bool(false) 
     ["listed_count"]=> 
     int(1) 
     ["time_zone"]=> 
     string(26) "Pacific Time (US & Canada)" 
     ["is_translator"]=> 
     bool(false) 
     ["profile_background_color"]=> 
     string(3) "fff" 
     ["geo_enabled"]=> 
     bool(false) 
     ["notifications"]=> 
     bool(false) 
     ["follow_request_sent"]=> 
     bool(false) 
     ["lang"]=> 
     string(2) "en" 
     ["profile_background_image_url"]=> 
     string(69) "http://a0.twimg.com/profile_background_images/422730827/photo__1_.JPG" 
     ["friends_count"]=> 
     int(15) 
     ["statuses_count"]=> 
     int(50) 
     ["verified"]=> 
     bool(false) 
     ["profile_link_color"]=> 
     string(6) "0084B4" 
     ["default_profile_image"]=> 
     bool(false) 

답변

-1
// ***********************************-={ 2012-12-08 - WB }=-*********************************** 
// COLLECT THE FREINDS ARRAY 
// ********************************************************************************************* 
$friends = $connection->get('statuses/friends_timeline'); //method that catches my friends'statuses on Twitter. 





// ***********************************-={ 2012-12-08 - WB }=-*********************************** 
// PRINTS THE ENTIRE ARRAY TO THE SCREEN 
// ********************************************************************************************* 
// var_dump($friends); //STILL WORKS, BUT TRY THE METHOD BELOW 

//This Is Just A Cleaner Way Of Dumping The Array 
print "<PRE><FONT COLOR=ORANGE>"; print_r($friends); print "</FONT></PRE>"; 




// ***********************************-={ 2012-12-08 - WB }=-*********************************** 
// TO WORK WITH INDVIDUAL KEY/VALUE PAIRS FROM ARRAY 
// AS YOU MENTIONED YOU WERE ATTEMPTING TO GET YOUR FRIENDS PIC 
// ********************************************************************************************* 
print "<BR>".$friends[5]; 
print "<BR>".$friends[6]; 
print "<BR>".$friends[7]; 
print "<BR>".$friends[8];// This One Should Be What You Are Looking For 
print "<BR>".$friends[9]; 
print "<BR>".$friends[10]; 





// ***********************************-={ 2012-12-08 - WB }=-*********************************** 
// NOT NEEDED UNLESS YOUR LOOKING TO RANDOMIZE LATER ON 
// ********************************************************************************************* 
//shuffle($friends);//THIS WILL PRINT THE ARRAY IN A RANDOM ORDER EACH TIME IT IS CALLED 






// ***********************************-={ 2012-12-08 - WB }=-*********************************** 
// YOUR IF STATEMENT IS GOOD PRACTICE. 
// SO IF WE DO NOT HAVE THE POPULATED ARRAY, LETS STOP HERE 
// ********************************************************************************************* 
if(is_array($friends)){ 
    $counter = 0; //LETS ADD A COUNTER TO USE IN THE PRINT STATEMENT BELOW 
    foreach ($friends as &$friend_data) {//WORK WITH EACH KEY. THERE ARE ALOT OF WAYS TO DO THIS LIKE WITH for(), or explode(), OR array_walk ETC... 
     print "Key: ".$counter."<BR>".$friend_data; 
     $counter++; //Just Adds 1 To The Counter For Each Loop 

    }//CLOSE YOUR FOR EACH STATEMENT 
} //CLOSE YOUR IF ARRAY EXISTS STATEMENT 










// ***********************************-={ 2012-12-08 - WB }=-*********************************** 
// FINALY I CLEARLY SEE IN YOUR CODE AS WELL AS YOUR STATEMENT YOU WANT ONE KEY VALUE PAIR. 
// SO HERE IS WHAT YOU ASKED FOR IN YOUR POST. 
// ********************************************************************************************* 
$friends = $connection->get('statuses/friends_timeline'); //COLLECT DATA. POPULATE YOUR ARRAY 
//var_dump($friends); //REMOVE COMMENT IF THE KEY/VALUE PAIR IS WRONG AND SELECT THE RIGHT ONE. 
$value = $friends[8]; //stick the right key val pair together and load it into the variable $value 
print "<img src='". $value."' width='100' height='100'/>"; //PRINT YOUR BUDDIES PIC TO THE PAGE. 

그것은 # 8처럼 보이는 그러나 나는 미스가 계산되는있을 수 있습니다.

설명해주십시오. 위의 코드는 Var 덤프 아래의 브라우저 창에 6 개의 키를 출력합니다. 어레이에는 원하는 값 쌍이 포함되어 있으므로 키 값 쌍이 들어 있습니다. $ arrayname [#];

그래서 id_str는 $ friends [5]가됩니다.

브라우저에 이것을 인쇄하면 분명하게 보이지만 말한 것처럼 말입니다. 희망이 도움이됩니다.

EDIT. 나는 이걸 입력하고 그냥 내가하는 일을하는 방법입니다. 그것은 또한 연설의 법 아래에 빠진다. 자신의 답변을 게시하려면이 페이지의 옵션보다 분명히 읽을 수없는 사람. 내가 시간을내어 무엇이든 타이핑하려고 노력한다면. 나는 그것을 어떻게 타이핑했는지 남아있을 것이다. 그리고 나는 그것을 필요에 따라 계속 고정 할 것입니다.

다른 사람들에게 비판할만한 것은 없지만 다른 사람들의 방식을 비판하는 사람들은 삶을 살아 가야합니다. 나는이 일에 대부분의 다른 사람들과 마찬가지로 프로그래머이다. 나의 일 스케줄에서 시간을 빼앗아가는 사람은 내가 다른 사람을 돕기 위해 내가 수년간 또는이 바로 그 날을 기쁘게한다.

나는 또한 나를 위해 힘든 일을하는이 남자를 따라하기 위해 시간을 보냈다. 그리고 나는 곧 그 사건이 아니라는 사실을 알아 냈습니다. 그는 모두에게 거시기에 불과합니다.

그래서, 만약 내가 이런 식으로 입력하십시오. 그 녀석과 똑같아. 또는 심지어 이것처럼. 나는 아직도 내 포인트를 얻는다.

또한 Charles는 내가 본 방식에 대해 아무 말도하지 않은 첫 번째 사람입니다. 게다가 내 시프트 키는 당신이 아니라 구타를 가져옵니다. 사실이 메시지의 창조에 찰스는 아무런 해를 입지 않았습니다.

도움을 받으려는 프로그래머가 있습니다. 그렇다면 저 밑에 몇 년이나 지낸 사람들은 그들이 모두 알고 있다고 생각하고, 생각하는 모든 사람들을 쓰레기처럼 덜어주고 싶다고 생각합니다. 모두들 그의 지위를 따르고 당신이 결론을 내리는 지보십시오.

+0

나는 그가 행동에서 이것을 보았을 때 분명하다. IE : 복사/붙여 넣기 내가 입력 할 시간을 가져간 것, 계속 진행되는 내용을 이해할 것입니다. 하지만 Clarity Sake를 위해서 ... 조금 자세히 추가했습니다. –

+0

".. 그러나, 나는 단지 내 친구들의 프로필 이미지를보고 싶다. 그래서 이걸 내가 붙잡 았던 것이고 아무것도 돌려주지 않는다."모든 수단으로 ... 당신의 말로 설명하라. . 그리고 자신의 타자를 치는 습관으로. 부디. –

+0

죄송합니다. 자신에게 더 나은 질문을 설명해 드리겠습니다. 그는 그의 친구들의 "프로필 이미지를 잡기"를 원합니다. 그래서 이것은 그가 "그것을 잡으려고 한 것이고 아무것도 돌려주지 않습니다." 하나의 키 값 쌍이 참조됩니다. 자신을 설명하십시오. 당신이이 남자 머리에있는 것 같아서. –

관련 문제