Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !

like image 793
NSS Avatar asked Mar 24 '23 12:03

NSS


1 Answers

Finally, I removed OAuth token and it works fine !

See code below :

STTwitterAPIWrapper *twitter = [STTwitterAPIWrapper twitterAPIApplicationOnlyWithConsumerKey:OAUTH_CONSUMER_KEY consumerSecret:OAUTH_CONSUMER_SECRET];

[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {

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

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

} errorBlock:^(NSError *error) {
    NSLog(@"-- error %@", error);
}];
like image 62
NSS Avatar answered Apr 05 '23 23:04

NSS