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 !
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);
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With