objective c - How do you get the "images" from a twitter feed to show in an iOS app -


i have code accesses twitter feed , puts text table. edited code display text in custom fashion in separate views, wanted grab images tweets well, , despite on hour searching not find single reference. have seen how "post" images, clear, need , "display" images tweet in question.

here highlights code handles twitter access:

-(void)twittertimeline {     acaccountstore *account = [[acaccountstore alloc] init];      acaccounttype *accounttype = [account accounttypewithaccounttypeidentifier:acaccounttypeidentifiertwitter];      [account requestaccesstoaccountswithtype:accounttype options:nil completion:^(bool granted, nserror *error) {         if (granted == yes)         {             nsarray *arrayofaccounts = [account accountswithaccounttype:accounttype];              if ([arrayofaccounts count] > 0)             {                 acaccount *twitteraccount = [arrayofaccounts lastobject];   // last account on list of accounts                 nsurl *requestapi = [nsurl urlwithstring:@"https://api.twitter.com/1.1/statuses/user_timeline.json"];                   nsmutabledictionary *parameters = [[nsmutabledictionary alloc] init];                  [parameters setobject:@"30" forkey:@"count"];                  [parameters setobject:@"1" forkey:@"incude_entities"];                  slrequest *posts = [slrequest requestforservicetype:slservicetypetwitter requestmethod:slrequestmethodget url:requestapi parameters:parameters];                  posts.account = twitteraccount;                  [posts performrequestwithhandler:^(nsdata *response, nshttpurlresponse *urlresponse, nserror *error) {                     if (response)                     {                         // todo: might want check urlresponse.statuscode stop                         nserror *jsonerror;  // use new instance here, don't want overwrite error got slrequest                         nsarray *array =[nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingmutableleaves error:&jsonerror];                         if (array) {                             if ([array iskindofclass:[nsarray class]]) {                                 self.array = array;                                 nslog(@"resulted array: %@",self.array);                             }                             else {                                 // should never happen                                 nslog(@"not array! %@ - %@", nsstringfromclass([array class]), array);                             }                         }                         else {                             // todo: handle error in release version, don't dump out information                             nslog(@"json error %@", jsonerror);                             nsstring *datastring = [[nsstring alloc] initwithdata:response encoding:nsutf8stringencoding];                             nslog(@"received data: %@", datastring ? datastring : response);    // print string representation if response string, or print raw data object                         }                     }                     else {                         // todo: show error information user if request failed                         nslog(@"request failed %@", error);                     }                      self.array = [nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingmutableleaves error:&error];                      if (self.array.count != 0)                     {                         dispatch_async(dispatch_get_main_queue(), ^{                             [self.tableview reloaddata];    // part loads table - important!                         });                      }                 }];             }         }         else         {             nslog(@"%@", [error localizeddescription]);         }      }]; } 

and here how display tweet

-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellid = @"cellid";      uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellid];      if (cell == nil)     {         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid];     }      nsdictionary *tweet = _array[indexpath.row];      cell.textlabel.text = tweet[@"text"];     //nsstring *element = [myarray objectatindex:2];     //nsstring *element = myarray[2];   // created custom views show text, kept table testing purposes     templateview *tempview = [viewarray objectatindex:testcounter];     tempview.tweetview.text = tweet[@"text"];     // -> hoping // tempview.contentview.image = tweet[@"image"];     testcounter++;     if (testcounter >= 30)     {         testcounter = 0;     }      return cell; } 

i took out key lines think need look:

tempview.tweetview.text = tweet[@"text"]; tempview.contentview.image = tweet[@"image"]; 

// hoping latter work first 1 does, it's not simple

this might not possible, if so, how images "link" (url) , make sure image , not video or other website?

i set "word search" grab text starting http tweet , generate url string

twitterkit doesn't seem support images publicly.. i'm having same stupid issue. api internally holds images when using built in tableview , datasource.. requires listid , slug.. however, when want images via json, out of luck! twtrtweet object doesn't have entities or media properties!

not sure how can develop such awful api.. in case, reversed server calls made internally , found sends other "undocumented" parameters..

example:

twtrapiclient *client = [[twtrapiclient alloc] init];  nsstring *endpoint = @"https://api.twitter.com/1.1/statuses/user_timeline.json";  nsdictionary *params = @{@"screen_name":@"screen_name_here",                              @"count": @"30"}; 

will return no media.. if have @"include_entities" : @"true".

solution:

twtrapiclient *client = [[twtrapiclient alloc] init];  nsstring *endpoint = @"https://api.twitter.com/1.1/statuses/user_timeline.json";  nsdictionary *params = @{@"screen_name":@"screen_name_here",                          @"count": @"30",                          @"tweet_mode": @"extended"}; 

with tweet_mode set extended (tweet_mode undocumented parameter), return media part of response.. includes "type" "photo" images.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -