STTwitter library returns an error when retrieving a list of tweets for a keyword with special characters

I want to get a list of tweets using the Twitter Search API. But recently, twitter has launched a new version of version 1.1 and requires authorization. I use the STTwitter library to interact with the Twitter API.

I am using the STTwitter_ios project, which you can find here: https://github.com/nst/STTwitter/tree/master/ios

Now I have written one example function: fetchTweets. Authorization works successfully, and I get a list if I search for a word (without spaces or special characters). But when I try to find a keyword with spaces or special characters such as "New York", "New or York", etc., then it returns an error:

In the method, - (void) connectionDidFinishLoading: (NSURLConnection *) connection
I get an error: {"errors": [{"message": "Failed to 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 would be appreciated!

Thanks!

+4
source share
3 answers

Finally, I removed the OAuth token and it works great!

See the 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); }]; 
+5
source

I am Nicholas Seriot, creator of STTwitter.

The problem you encountered was a mistake, and I just fixed it .

+2
source

Try adding HTML code for your keywords. For instance,

  [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] 
0
source

Source: https://habr.com/ru/post/1486752/


All Articles