EzDevInfo.com

STTwitter

A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1

STTwitter CFNetwork internal error NSURLRequest

After looking at this link API mode error I corrected some code using STTwitter. This eradicated one error but made me notice a new CFNetwork error. Whenever I try to fetch statuses using either getHomeTimelineSinceID or getUserTimelinewithScreenName, the error "CFNetwork internal error (0xc01a:/SourceCache/CFNetwork/CFNetwork-695.1.5/Foundation/NSURLRequest.mm:798)" pops up in the debugger. After debugging I found the error pops right after [r Asynchronous] (line 272 of STTwitterAppOnly.m). I got to this spot by stepping into verifyCredentialsWithSuccessBlock.

The code I am currently using:

   [twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {

    [twitter getHomeTimelineSinceID:nil
                               count:20
                        successBlock:^(NSArray *statuses) {

                            NSLog(@"-- statuses: %@", statuses);


                            self.twitterFeed = statuses;

                            [self.tableView reloadData];

                        } errorBlock:^(NSError *error) {
                        }];

And I have also tried:

        [twitter getUserTimelineWithScreenName:@"Dandelion_2014"
                              successBlock:^(NSArray *statuses) {

                                  self.twitterFeed = [NSMutableArray arrayWithArray:statuses];

                                  [self.tableView reloadData];

                              } errorBlock:^(NSError *error) {

                                  NSLog(@"%@", error.debugDescription);

                              }];

I'm not sure what is causing this error, does anybody have insight?


Source: (StackOverflow)

Posting tweet to twitter using STTwitter in iOS

I am using STTwitterAPI for creating app that performs all operations of twitter . I am receiving timeline feeds. But how to post the tweet using the same API . I searched for this however i found only SLComposeViewController to post the tweet which will present the controller then we can post tweet with location and image. What i am trying to do is create my own compose view . So if any one has some solution for this please do write to this thread .

Thnx and Regards,

pagyy


Source: (StackOverflow)

Advertisements

Objc to swift bridge `use of undeclared identifier 'cocoarr'`

I'm combining Swift and Objective-C in the same project. I am trying to use STTwitter cocoapod like this:

// objective-c
// STTwitter category method
//
- (void)getStatusesLookupTweetIDs:(NSArray *)tweetIDs 
                     successBlock:(void (^)(NSArray *))successBlock 
                       errorBlock:(void (^)(NSError *))errorBlock {

    [self getStatusesLookupTweetIDs:tweetIDs
                    includeEntities:@(YES)
                           trimUser:@(YES)
                                map:@(YES)
                       successBlock:successBlock
                         errorBlock:errorBlock];
}

Swift Code

// swift
twitterApi.getStatusesLookupTweetIDs(ids, successBlock: { (tweets: [AnyObject]!) -> Void in
    process(tweets)
    finish()
}, errorBlock: { (err) -> Void in
    error(err)
})

Everything looks fine in Obj-C (I tried not investigate variable passed to successBlock, they all have valid values). But in Swift, when successBlock gets executed, tweets was:

Printing description of tweets:
([AnyObject]!) tweets = 1 value {
  [0] = <error: use of undeclared identifier 'cocoarr'
error: 1 errors parsing expression
>

}

How do I fix this and pass NSArray into Swift? (No compile error)


Source: (StackOverflow)

STTwitter Library returns an error when getting tweets list for keyword with special characters

I want to get tweets list using Twitter Search API. But Recently twitter has launched New version-1.1 and it requires authorization. I'm using STTwitter library for interacting with Twitter API.

I'm using STTwitter_ios project which you can find from here : https://github.com/nst/STTwitter/tree/master/ios

Now, I have written one sample function: fetchTweets. Authorization works successful and I'm getting the list if i search for the word (Without spaces or special characters). But When I try to search keyword with spaces or Special characters like "New york", @"New or York", etc.. then it returns error :

In the method , - (void)connectionDidFinishLoading:(NSURLConnection *)connection
I'm getting error : {"errors":[{"message":"Could not authenticate you","code":32}]}

- (void) fetchTweets {


STTwitterAPIWrapper *twitter = [STTwitterAPIWrapper twitterAPIWithOAuthConsumerName:OAUTH_CONSUMER_NAME  consumerKey:OAUTH_CONSUMER_KEY consumerSecret:OAUTH_CONSUMER_SECRET oauthToken:OAUTH_TOKEN oauthTokenSecret:OAUTH_SECRET_TOKEN];

    NSString *query = @"New york";
    NSString *searchQuery = [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    [twitter getSearchTweetsWithQuery:searchQuery successBlock:^(NSDictionary *searchMetadata, NSArray *statuses) {
        NSLog(@"Search data : %@",searchMetadata);
        NSLog(@"\n\n Status : %@",statuses);
    } errorBlock:^(NSError *error) {
        NSLog(@"Error : %@",error);
    }];
}

Any help or suggestions will be appreciated !

Thanks !


Source: (StackOverflow)

Is there a method that gets bulk tweets in sttwitter?

Is there a method that exposes https://dev.twitter.com/docs/api/1.1/get/statuses/lookup in STTwitter?

I want to lookup and get the statuses for all the tweetId's in an array.


Source: (StackOverflow)

One time login with twitter using STTwitterAPI

How can i check user is already login with twitter or not by using its authToken and authTokenSecret?

I am using this code but its return value without wait for completing the block execution. How to use semaphore or something else to wait until block execute then function return its value.

- (BOOL)isTwitterLogin
{
  __block BOOL value;


    NSString *oauthToken=[[NSUserDefaults standardUserDefaults] valueForKey:@"iNtellTwitterToken"];
    NSString *oauthTokenSecret=[[NSUserDefaults standardUserDefaults] valueForKey:@"iNtellTwitterTokenSecret"];


    STTwitterAPI *twitterAPI = [STTwitterAPI twitterAPIWithOAuthConsumerKey:kTwitterConsumerKey consumerSecret:kTwitterConsumerSecret oauthToken:oauthToken oauthTokenSecret:oauthTokenSecret];

    [twitterAPI verifyCredentialsWithSuccessBlock:^(NSString *username)
     {
         /// we still good to go
         value=1;
     } errorBlock:^(NSError *error)
     {
         /// token has expired. User needs to login again
         value=0;
     }];
    return value;
}

i am looking for best way to execute this method..

Thanks in advance!!!


Source: (StackOverflow)

Parsing specified Twitter feed with JSON

I am currently making an app in which I would like to display a company twitter feed in a TableView. I have created a TableView (shown below, and I am linked it to my code. The problem I am facing now is predefining a twitter user, getting the feed, and parsing the data. I have come close to getting the twitter feed via STTwitter API and the consumer key & consumer secret. However, I am getting a 401 authentication error. I am at a loss for connecting my feed, and I have never worked with JSON in my life, so this is a pretty difficult task for me. Apart from the API, I have tried the code below, which results in a blank tweet.

#import "FeedController3.h"
#import "FeedCell3.h"
#import "FlatTheme.h"

@interface FeedController3 ()

@property (nonatomic, strong) NSArray* profileImages;

@end

@implementation FeedController3

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString* boldFontName = @"Avenir-Black";

    [self styleNavigationBarWithFontName:boldFontName];

    self.title = @"Twitter Feed";

    self.feedTableView.dataSource = self;
    self.feedTableView.delegate = self;

    self.feedTableView.backgroundColor = [UIColor whiteColor];
    self.feedTableView.separatorColor = [UIColor colorWithWhite:0.9 alpha:0.6];

    self.profileImages = [NSArray arrayWithObjects:@"profile.jpg", @"profile-1.jpg", @"profile-2.jpg", @"profile-3.jpg", nil];

    [self getTimeLine];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    //return _dataSource.count;
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    /*
    FeedCell3* cell = [tableView dequeueReusableCellWithIdentifier:@"FeedCell3"];

    cell.nameLabel.text = @"Laura Leamington";
    cell.updateLabel.text = @"This is a pic I took while on holiday on Wales. The weather played along nicely which doesn't happen often";

    cell.dateLabel.text = @"1 hr ago";
    cell.likeCountLabel.text = @"293 likes";
    cell.commentCountLabel.text = @"55 comments";

    NSString* profileImageName = self.profileImages[indexPath.row%self.profileImages.count];
    cell.profileImageView.image = [UIImage imageNamed:profileImageName];

    return cell;
    */

    FeedCell3* cell = [tableView dequeueReusableCellWithIdentifier:@"FeedCell3"];

    NSDictionary *tweet = _dataSource[[indexPath row]];

    cell.nameLabel.text = @"<Company Name>";

    cell.updateLabel.text = tweet[@"text"];

    cell.dateLabel.text = @"1 hr ago";
    cell.likeCountLabel.text = @"293 likes";
    cell.commentCountLabel.text = @"55 comments";

    NSString* profileImageName = self.profileImages[indexPath.row%self.profileImages.count];
    cell.profileImageView.image = [UIImage imageNamed:profileImageName];

    return cell;


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)styleNavigationBarWithFontName:(NSString*)navigationTitleFont{

    /*
    UIColor* color = [UIColor whiteColor];
    [FlatTheme styleNavigationBar:self.navigationController.navigationBar withFontName:navigationTitleFont andColor:color];
     */
    //[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:9.0f/255.0f green:49.0f/255.0f blue:102.0f/255.0f alpha:1.0f]];


    UIImageView* searchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search.png"]];
    searchView.frame = CGRectMake(0, 0, 20, 20);

    UIBarButtonItem* searchItem = [[UIBarButtonItem alloc] initWithCustomView:searchView];

    self.navigationItem.rightBarButtonItem = searchItem;
    /*
    UIButton* menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 28, 20)];
    [menuButton setImage:[UIImage imageNamed:@"menu.png"] forState:UIControlStateNormal];
    [menuButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem* menuItem = [[UIBarButtonItem alloc] initWithCustomView:menuButton];
    self.navigationItem.leftBarButtonItem = menuItem;
     */
}

-(IBAction)dismissView:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)getTimeLine {
    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];

                 NSURL *requestURL = [NSURL URLWithString:
                                      @"https://api.twitter.com/1.1/statuses/user_timeline.json"];

                 NSDictionary *parameters =
                 @{@"screen_name" : @"@RileyVLloyd",
                   @"include_rts" : @"0",
                   @"trim_user" : @"1",
                   @"count" : @"20"};

                 SLRequest *postRequest = [SLRequest
                                           requestForServiceType:SLServiceTypeTwitter
                                           requestMethod:SLRequestMethodGET
                                           URL:requestURL parameters:parameters];

                 postRequest.account = twitterAccount;

                 [postRequest performRequestWithHandler:
                  ^(NSData *responseData, NSHTTPURLResponse
                    *urlResponse, NSError *error)
                  {
                      self.dataSource = [NSJSONSerialization
                                         JSONObjectWithData:responseData
                                         options:NSJSONReadingMutableLeaves
                                         error:&error];

                      if (self.dataSource.count != 0) {
                          dispatch_async(dispatch_get_main_queue(), ^{
                              [self.feedTableView reloadData];
                          });
                      }
                  }];
             }
         } else {
             // Handle failure to get account access
         }
     }];
}

enter image description here


Source: (StackOverflow)

Getting profile image in iOS via STTwitter

I am using the the STTwitter API to make an App only twitter Feed. I have successfully output the tweet to the table cell, but now I'm attempting to connect user profile images and I am running in to some problems. I tried implementing the code I found here, but I was getting an error stating "No known class method for selector 'imageWithContentsOfURL:'" so I fixed the problem by replacing UIImage with CIImage. However, now my app is crashing because I'm trying to output a CIImage to an UIImageView. My code and errors are as follows:

Code:

- (void)viewDidLoad
{
    [super viewDidLoad];


    NSString* boldFontName = @"Avenir-Black";

    [self styleNavigationBarWithFontName:boldFontName];

    self.title = @"Twitter Feed";

    self.feedTableView.dataSource = self;
    self.feedTableView.delegate = self;

    self.feedTableView.backgroundColor = [UIColor whiteColor];
    self.feedTableView.separatorColor = [UIColor colorWithWhite:0.9 alpha:0.6];

    //self.profileImages = [NSArray arrayWithObjects:@"profile.jpg", @"profile-1.jpg", @"profile-2.jpg", @"profile-3.jpg", nil];

    STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"stuff"
                                                            consumerSecret:@"stuff"];

    [twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {

        [twitter getUserTimelineWithScreenName:@"RileyVLloyd"
                                  successBlock:^(NSArray *statuses) {
                                      self.twitterDataSource = [NSMutableArray arrayWithArray:statuses];

                                      for (int i=1; i <= _twitterDataSource.count; i++) {
                                      NSLog(@"%d", i);
                                      NSDictionary *tweetDictionary = self.twitterDataSource[i];
                                      NSString *final = tweetDictionary[@"profile_image_url"];
                                      NSLog(@"%@", final);
                                      }

                                      [self.feedTableView reloadData];
                                  } errorBlock:^(NSError *error) {
                                      NSLog(@"%@", error.debugDescription);
                                  }];

    } errorBlock:^(NSError *error) {
        NSLog(@"%@", error.debugDescription);
    }];
    //[self getTimeLine];

}



#pragma mark Table View Methods

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.twitterDataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID =  @"FeedCell3" ;

    FeedCell3 *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

    if (cell == nil) {
        cell = [[FeedCell3 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }


    cell.nameLabel.text = @"RileyVLloyd";


    cell.likeCountLabel.text = @"293 likes";
    cell.commentCountLabel.text = @"55 comments";

    //NSString* profileImageName = self.profileImage[indexPath.row%self.profileImage.count];
    cell.profileImageView.image = _profileImage;

    NSInteger idx = indexPath.row;
    NSDictionary *t = self.twitterDataSource[idx];

    cell.updateLabel.text = t[@"text"];

    cell.dateLabel.text = @"1 day ago";

    return cell;
}

Source: (StackOverflow)

Upload Multiple Photos to Twitter Using STTwitter

I know that you can put up to four images in a tweet, so I was wondering if that was possible, possibly using STTwitter I know that you can upload one image using this method in STTwitter, but as far as I know this method doesn't support multiple images:

- (NSObject<STTwitterRequestProtocol> *)postMediaUpload:(NSURL *)mediaURL
                                    uploadProgressBlock:(void(^)(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite))uploadProgressBlock
                                           successBlock:(void(^)(NSDictionary *imageDictionary, NSString *mediaID, NSString *size))successBlock
                                             errorBlock:(void(^)(NSError *error))errorBlock

Worth mentioning I'm building this into an iOS app using Objective-C


Source: (StackOverflow)

NSDateFormatter not Working for Twitter date

I am trying to format a date i am getting from twitter using the STTwitter library.

However the code that I've tried so far has not worked.

Code for getting the date from twitter:

NSString *dateString = [status valueForKey:@"created_at"];

This returns the time, date, time zone and year in which the tweet was made which looks messy.

I tried using the following code to convert this and make it neater:

NSDateFormatter *dateFormatter =[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"MMddHHmm"];

NSDate *dateFromString = [dateFormatter dateFromString:dateString];
NSLog(@"%@", dateFromString);


dateFormatter =[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"dd MMMM' at 'hhmm a"];
NSString *mydate=[dateFormatter stringFromDate:dateFromString];

And then try to put the result in a text label:

cell.detailTextLabel.text = my date;

Ive tried many different variations of the Date Formatter but none have worked and i have no idea why.

Thanks for your help :)


Source: (StackOverflow)

How to do login in Twitter using STTwitter for OSX?

Hello,

I am developing a Twitter client for OSX using STTwitter library. I use this code to do login:



    - (void) loginWithUser:(NSString*) user
                  password:(NSString*) password {
        twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:kOAuthConsumerKey
                                                consumerSecret:kOAuthConsumerSecret
                                                      username:user
                                                      password:password];

        [twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
            _status = [NSString stringWithFormat:@"Access granted for %@", username];
            _isConnected = YES;
        } errorBlock:^(NSError *error) {
            _isConnected = NO;
            _status = [error localizedDescription];
            NSLog(@"Status: %@",_status);
        }];
    }

I can read direct messages using my personal Twitter account and other development Twitter account but if I try to use other Twitter account from my beta testers I can not read the direct messages.

The error message is:

This application is not allowed to access or delete your direct messages.

I tried to use an OSX system account to do login using this code:



    - (void) loginWithSystemAccount {
        twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];
        [twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
            _status = [NSString stringWithFormat:@"Access granted for %@", username];
            _isConnected = YES;
        } errorBlock:^(NSError *error) {
            _isConnected = NO;
            _status = [error localizedDescription];
            NSLog(@"Status: %@",_status);
        }];
    }

But I can read direct messages using a system account.

I checked the OSX Demo in STTwitter git repository but I could not find a solution. How can I do a right login in Twitter for all users to read direct messages?

Thanks in advance


Source: (StackOverflow)

Compiling issues on STTwitter for OSX App

I've been working on an app for OSX (not my own, one that I am to maintain) that needs Twitter integrations and found the STTwitter wrapper. It says it's compatible down to OSX 10.7. However, when I try to compile it, I run into several compilation issues that I've tracked I think I've tracked down to not being able to compile with Objective-C literal subscripts.

I tries using the workaround suggested across the web for adding my own interfaces, but that didn't seem to help.

The first compilation error I get is "Array subscript is not an integer" at the following chunk of code in NSError+STTwitter.m:

    NSMutableDictionary *md = [NSMutableDictionary dictionary];
    md[NSLocalizedDescriptionKey] = message;
    if(underlyingError) md[NSUnderlyingErrorKey] = underlyingError;
    if(rateLimitLimit) md[kSTTwitterRateLimitLimit] = rateLimitLimit;
    if(rateLimitRemaining) md[kSTTwitterRateLimitRemaining] = rateLimitRemaining;
    if(rateLimitResetDate) md[kSTTwitterRateLimitResetDate] = rateLimitResetDate;

If I comment that code out, just to see what happens (the literal substring I believe), I get more issues in STTwitterOS.m

NSString *value = [keyValue[1] stringByReplacingOccurrencesOfString:@"\"" withString:@""];

[md setObject:value forKey:keyValue[0]];

Those give "Bad receiver type NSArray" and "Sending NSArray to parameter of incompatible type 'id

Any help would be appreciated. My objective c coding isn't that great....


Source: (StackOverflow)

Check If Tweet with ID Has Been Retweeted

I have an app that shows tweets on a map and when one is selected it shows more details for the tweet (twitter handle, the tweet, profile pic, etc.) There are buttons for favoriting and retweeting the tweet. The app uses STTwitter to interact with the Twitter API and authenticates the user of the app with twitter = [STTwitterAPI twitterAPIOSWithFirstAccount]; For retweeting and favoriting in the tweet detail view, I do this:

- (IBAction)retweet:(id)sender {
    [twitter postStatusRetweetWithID:tweetID successBlock:^(NSDictionary *status) {

        UIAlertView *retweetSuccess = [[UIAlertView alloc]initWithTitle:@"Retweeted!" message:@"You have retweeted this post." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [retweetSuccess show];

    } errorBlock:^(NSError *error) {

        UIAlertView *retweetFailure = [[UIAlertView alloc]initWithTitle:@"Retweet Failed!" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [retweetFailure show];

    }];
}

- (IBAction)favorite:(id)sender {
    [twitter postFavoriteCreateWithStatusID:tweetID includeEntities:nil successBlock:^(NSDictionary *status) {

        UIAlertView *favoriteSuccess = [[UIAlertView alloc]initWithTitle:@"Favorited!" message:@"You have favorited this post." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [favoriteSuccess show];

    } errorBlock:^(NSError *error) {

        UIAlertView *favoriteFailure = [[UIAlertView alloc]initWithTitle:@"Favorite Failed!" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [favoriteFailure show];

    }];
}

How can I detect if a tweet has already been retweeted or favorited by the user so I can show a different button image for the retweet and favorite buttons?


Source: (StackOverflow)

STTwitter timeout issue with verifyCredentialsWithSuccessBlock in iOS 9

I am trying to fetch tweets for a particular account using STTwitter but getting connection timeout error in iOS 9 for verifyCredentialsWithSuccessBlock method. I am getting the tweets properly in iOS 8.4 but having trouble in iOS 9. There is no issue in performing login with twitter using STTWitter. Following is my code:

STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:_consumerKeyTextField
                                                                consumerSecret:_consumerSecretTextField];

[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
 [twitter getUserTimelineWithScreenName:@"Ointeractive"
                     successBlock:^(NSArray *statuses) {

       self.statuses=[NSArray arrayWithArray:statuses];
       Reachability* wifiReach = [Reachability reachabilityForLocalWiFi];

       NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
       if  (netStatus==ReachableViaWiFi) {
            [self updateTwitterLabelAndImage];
            [self addSwipeToTwitterLabel];
       }
    } errorBlock:^(NSError *error) {
      // ...

      NSLog(@"-- %@", [error localizedDescription]);
    }];

 } errorBlock:^(NSError *error) {
 }];

Following is the error that I'm getting:

Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x13889ca50 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey=https://api.twitter.com/oauth2/token, NSErrorFailingURLKey=https://api.twitter.com/oauth2/token, _kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4, NSLocalizedDescription=The request timed out.}}, NSErrorFailingURLStringKey=https://api.twitter.com/oauth2/token, NSErrorFailingURLKey=https://api.twitter.com/oauth2/token, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}

I tried increasing the timeout interval and also tried disabling the App Transport Security using instructions in this doc but still no luck. Is there any solution to this or will I have to discard STTwitter and switch to twitter integration using fabric?


Source: (StackOverflow)

STTwitter - How can i take just 5 record on Stream API

I used STTwitter in my project and I want 5 tweet on some coordinates. There is question like this but i dont understand.

How can I stop a stream when using STTWitter

I tried like this, but its not stop at 5 records and always return tweet.

-(void)getTwitterActivityWithLocation:(CLLocation *)location withSuccessBlock:(void(^)(NSMutableArray *activities))successBlock
{
    STTwitterAPI *twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];
    [twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
        NSString *latRectLeft = [[NSString alloc] initWithFormat:@"%f",location.coordinate.latitude];
        NSMutableArray *data = [[NSMutableArray alloc] init];

        id twitterRequest = [twitter postStatusesFilterUserIDs:nil keywordsToTrack:nil locationBoundingBoxes:@[@"28.9986108",@"41.0377369",@"28.9996108",@"41.0387369"] delimited:@20 stallWarnings:nil progressBlock:^(NSDictionary *tweet) {


            if ([data count] > 4) {
                [twitterRequest cancel];
                successBlock(data);
            }
            else if (([[tweet valueForKey:@"geo"] valueForKey:@"coordinates"] != nil)) {

                if (![tweet isEqual:nil] && [tweet count] > 0)
                {
                    NSLog(@"%@",[tweet valueForKey:@"text"]);
                    [data addObject:tweet];
                }

            }

        } stallWarningBlock:nil
            errorBlock:^(NSError *error) {
                NSLog(@"Error");
        }];


    } errorBlock:^(NSError *error) {
        NSLog(@"%@",[error description]);
    }];


}

If take [twitterRequest cancel]; line to outside of block, its work. But this time i don't have any tweet record.

How can i solve this ?


Source: (StackOverflow)