2012-10-09 3 views
-1

트위터 피드를 가져 오려고합니다. 나는twitter api에서 데이터를 가져 오는 중

https://twitter.com/status/user_timeline/wwwkrcgenkbe.json?count=25&from=wwwkrcgenkbe 

URL을 나는 다음과 같은 방법으로 그 일을하고

[ 

    { 
     "place": null, 
     "retweeted": false, 
     "in_reply_to_status_id_str": null, 
     "in_reply_to_screen_name": null, 
     "possibly_sensitive": false, 
     "in_reply_to_status_id": null, 
     "truncated": false, 
     "in_reply_to_user_id_str": null, 
     "user": { … }, 
     "in_reply_to_user_id": null, 
     "contributors": null, 
     "coordinates": null, 
     "retweet_count": 0, 
     "favorited": false, 
     "created_at": "Tue Oct 09 08:54:53 +0000 2012", 
     "geo": null, 
     "source": "<a href=\"http://www.facebook.com/twitter\" rel=\"nofollow\">Facebook</a>", 
     "id_str": "255592155345727489", 
     "id": 255592155345727500, 
     "possibly_sensitive_editable": true, 
     "text": "Vorige week won Nele Vangeneugden het shirtje dat Jelle Vossen droeg in de Europa League wedstrijd tegen... http://t.co/mwxSsBLP" 
    }, 

다음 JSON 형식에게 제공이 URL을 사용하고 있습니다. 먼저이 메서드를 추가합니다.

for (NSDictionary *genkInfo in tweets) { 
      NSLog(@"Komt in deze methode"); 
      [Twitter twitterWithGenkInfo:genkInfo inManagedObjectContext:document.managedObjectContext]; 
      NSLog(@"tweets: %@", tweets); 
     } 

그런 다음이 값으로 핵심 데이터 데이터베이스에 값을 저장합니다.

+ (Twitter *)twitterWithGenkInfo:(NSDictionary *)genkInfo 
       inManagedObjectContext:(NSManagedObjectContext *)context 
{ 
    NSLog(@"till here"); 
    Twitter *twitter= nil; 
    NSLog(@"till here 2"); 
    twitter = [NSEntityDescription insertNewObjectForEntityForName:@"Twitter" 
               inManagedObjectContext:context]; 
    NSLog(@"tille here3"); 
    twitter.tweet  = [genkInfo objectForKey:TWITTER_TWEET]; 
    twitter.date  = [genkInfo objectForKey:TWITTER_DATE]; 
    NSLog(@"till here 4"); 
    NSLog(@"tweet is: %@",twitter.tweet); 
    NSLog(@"date is: %@",twitter.date); 

    return twitter; 
} 

이 방법은 내 View Controller에서 다음과 같은 방법으로 호출됩니다.

NSArray *tweets   = [GenkData getTweets]; 

for (NSDictionary *genkInfo in tweets) { 
       NSLog(@"Komt in deze methode"); 
       [Twitter twitterWithGenkInfo:genkInfo inManagedObjectContext:document.managedObjectContext]; 
      } 

하지만 항상이 오류가 발생합니다.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKey:]: unrecognized selector sent to instance 0x2751678' 

아무도 도와 줄 수 있습니까?

미리 감사드립니다.

로그 파일

Log is: (
     { 
     contributors = "<null>"; 
     coordinates = "<null>"; 
     "created_at" = "Tue Oct 09 12:53:08 +0000 2012"; 
     favorited = 0; 
     geo = "<null>"; 
     id = 255652115341508608; 
     "id_str" = 255652115341508608; 
     "in_reply_to_screen_name" = "<null>"; 
     "in_reply_to_status_id" = "<null>"; 
     "in_reply_to_status_id_str" = "<null>"; 
     "in_reply_to_user_id" = "<null>"; 
     "in_reply_to_user_id_str" = "<null>"; 
     place = "<null>"; 
     "possibly_sensitive" = 0; 
     "possibly_sensitive_editable" = 1; 
     "retweet_count" = 0; 
     retweeted = 0; 
     source = "<a href=\"http://www.facebook.com/twitter\" rel=\"nofollow\">Facebook</a>"; 
     text = "KRC Genk mobile: de Iphone APP (al meer dan 1 mnd beschikbaar) werd reeds 2226 keer gedownload, de Android APP... http://t.co/QidTcLJS"; 
     truncated = 0; 
     user =   { 
      "contributors_enabled" = 0; 
      "created_at" = "Fri Nov 20 18:57:28 +0000 2009"; 
      "default_profile" = 0; 
      "default_profile_image" = 0; 
      description = "The official twitter account from Belgian Soccer team KRC Genk. Belgium champions 2011. Qualified for UEFA Euro League 2012-2013."; 
      "favourites_count" = 1; 
      "follow_request_sent" = "<null>"; 
      "followers_count" = 4831; 
      following = "<null>"; 
      "friends_count" = 21; 
      "geo_enabled" = 0; 
      id = 91402003; 
      "id_str" = 91402003; 
      "is_translator" = 0; 
      lang = en; 
      "listed_count" = 94; 
      location = "Genk - Belgium"; 
      name = "KRC Genk"; 
      notifications = "<null>"; 
      "profile_background_color" = C0DEED; 
      "profile_background_image_url" = "http://a0.twimg.com/profile_background_images/84123014/youtubebg.jpg"; 
      "profile_background_image_url_https" = "https://si0.twimg.com/profile_background_images/84123014/youtubebg.jpg"; 
      "profile_background_tile" = 0; 
      "profile_image_url" = "http://a0.twimg.com/profile_images/654317237/twitter_thumb_normal.jpg"; 
      "profile_image_url_https" = "https://si0.twimg.com/profile_images/654317237/twitter_thumb_normal.jpg"; 
      "profile_link_color" = 0084B4; 
      "profile_sidebar_border_color" = C0DEED; 
      "profile_sidebar_fill_color" = DDEEF6; 
      "profile_text_color" = 333333; 
      "profile_use_background_image" = 1; 
      protected = 0; 
      "screen_name" = wwwkrcgenkbe; 
      "statuses_count" = 4230; 
      "time_zone" = "<null>"; 
      url = "http://www.krcgenk.be"; 
      "utc_offset" = "<null>"; 
      verified = 0; 
     }; 
    }, 
-[__NSCFNumber managedObjectContext]: unrecognized selector sent to instance 0x9331b40 
+0

'NSLog (@ 트윗 : % @ ", 트윗)의 출력을 출력합니다.'; – ilmiacs

+0

몇 가지 로그를 사용하여 내 게시물을 편집했습니다. getTweets에'[self executeGenkFetch : request]'의 출력 – Steaphann

+0

출력을 보내 주셔서 감사합니다. (아마도 키 '@ ""가 없습니다.). – ilmiacs

답변

0

executeGenkFetch 당신에게 하늘의 배열, 또는 빈 사전의 배열을 반환 할 것으로 보인다. @ilmiacs가 말했듯이, 트윗의 출력을 게시하십시오.

+0

첫 번째 답변에 감사드립니다. NSLog로 코드를 업데이트했습니다. 그러나 나는 그것이 그 기록에 도달하지 않는다고 생각한다. 아무것도 인쇄하지 않기 때문에 – Steaphann

관련 문제