STTwitter return nil iOS - ios

I'm using STTwitter Library (latest version) and trying to get tweets with authenticating by oAuth and specifically using the Application Only authentication which provide the bearer token.
I used the example code provided on GitHub but I do not getting neither success or error on the log out. This is my code :
STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:#"XXX"
consumerSecret:#"XXX"];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
[twitter getUserTimelineWithScreenName:#"sttwitter"
successBlock:^(NSArray *statuses) {
NSLog("successBlock : ", statuses);
} errorBlock:^(NSError *error) {
NSLog("errorBlock : ", error);
}];
} errorBlock:^(NSError *error) {
NSLog("errorBlock : ", error);
}];
Any help will be appreciated. I'm unable to find other twitter library specially for the api v1.1.

Related

Client is not permitted to perform this action STTwitter Error

I am using STTWitter for login using twitter. I have created an app.
When I try to call login method I am getting this error:
Error Domain=STTwitterTwitterErrorDomain Code=87 "
Client is not permitted to perform this action"
I am using this method to login:
STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:#"sqsamplekeyzWcESlRq3h"
consumerSecret:#"pgs0nD4qconsumeersecretkeyjOOzLk83obgw2s341WHlQ"
username:#"username"
password:#"password"];
[twitter verifyCredentialsWithUserSuccessBlock:^(NSString *username, NSString *userID) {
NSLog(#"YES");
// ...
} errorBlock:^(NSError *error) {
NSLog(#"%#",error);
// ...
}];

Get Twitter Members list

I m trying to get the list of the members of the group iOS Developers from Twitter Groups.
I m using STTwitterAPI. I used it to get the news feed of specific account, and it works so fine.
But when i tried to get the list of the members by using the functions (getListsMembersForSlug or getListsMembersForListID) it didn't work, I get the following error :
Description : Error Domain=STHTTPRequest Code=404 "The operation
couldn’t be completed. (STHTTPRequest error 404.)"
The code I m using is :
STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:#"MyConsumerKey" consumerSecret:#"MyconsumerSecret"];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
NSNumber *t = [NSNumber numberWithInt:1];
[twitter getListsMembersForSlug:#"iOS Developers" ownerScreenName:#"Gadget_Ry" orOwnerID:nil cursor:false includeEntities:false skipStatus:t successBlock:^(NSArray *users, NSString *previousCursor, NSString *nextCursor) {
NSLog(#"Ok");
} errorBlock:^(NSError *error) {
NSLog(#"NOk");
}];
} errorBlock:^(NSError *error) {
NSLog(#"%#", error.debugDescription);
}];
Can anyone help me please? Any suggestions! Tutorials! I'll be grateful :)
iOS Developers is not a slug.
iOS-Developers is a slug.
:-)

Simple twitter timeline iOS (only read tweets for no register user)

I want a twitter timeline to be displayed in a View, without the user having to put your twitter account, simplemete read the tweets and hashtag, of the accounts that I have selected during the programming of the app.
Is it possible? Where do I can find info for this?
All I see includes login in twitter.
Thank you.
You can use STTwitterAPIWrapper
Firstly using Twitter you must create an app , because you must use key and secret of your app in the code.
For example :
STTwitterAPIWrapper *twitter = [STTwitterAPIWrapper twitterAPIApplicationOnlyWithConsumerKey:YourTwitterConsumerKey
consumerSecret:YourTwitterConsumerSecret];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *username)
{
NSDictionary *parameters = #{#"q" : #"anyHashTag", #"result_type": #"recent", #"count": #"100"};
[twitter getSearchTweetsWithQuery:parameters successBlock:^(NSDictionary *searchMetadata, NSArray *statuses, NSString *refreshUrl) {
_refreshUrl = refreshUrl;
[self parseJSONString:statuses];
} errorBlock:^(NSError *error) {
//NSLog(#"-- error: %#", error);
}];
} errorBlock:^(NSError *error) {
//NSLog(#"--** error %#", error);
}];

How to get Token using Twitter API 1.1 in iOS

I am using "STTwitter" for getting token from below URL and request body
https://dev.twitter.com/docs/api/1.1/post/oauth2/token
request body code with URL is below
- (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBlock errorBlock:(void(^)(NSError *error))errorBlock {
[self postResource:#"oauth2/token"
baseURLString:#"https://api.twitter.com"
parameters:#{ #"grant_type" : #"client_credentials" }
useBasicAuth:YES
uploadProgressBlock:nil
downloadProgressBlock:nil
successBlock:^(id request, NSDictionary *requestHeaders, NSDictionary *responseHeaders, id json) {
NSString *tokenType = [json valueForKey:#"token_type"];
if([tokenType isEqualToString:#"bearer"] == NO) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterAppOnlyCannotFindBearerTokenInResponse userInfo:#{NSLocalizedDescriptionKey : #"Cannot find bearer token in server response"}];
errorBlock(error);
return;
}
self.bearerToken = [json valueForKey:#"access_token"];
successBlock(_bearerToken);
} errorBlock:^(id request, NSDictionary *requestHeaders, NSDictionary *responseHeaders, NSError *error) {
errorBlock(error);
NSLog(#"ERROR %#",[error description]);
}];
}
For Calling above method i am doing below code
STTwitterAppOnly *twitter1 = [[STTwitterAppOnly alloc] init];
[twitter1 verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
NSLog(#"sd");
[self.twitter getUserTimelineWithScreenName:#"SEREEN_NAME"
successBlock:^(NSArray *statuses) {
NSLog(#"ERROR ::: %#",[statuses description]);
// ...
} errorBlock:^(NSError *error) {
// ...
}];
} errorBlock:^(NSError *error) {
// ...
}];
I got below Error when perform above code...
**Error Domain=STHTTPRequest Code=99 "Unable to verify your credentials"**
Can you suggest me what I missed in my code?
My concern is that, I want to read twitter feed without login in Twitter.Only using "Consumer Key" and "Secret Key" with Twitter API V1.1.
Thanks
if you have ConsumerKey and ConsumerSecret you can try it
STTwitterAPIWrapper *twitterAPI = [[STTwitterAPIWrapper twitterAPIApplicationOnlyWithConsumerKey:#"Your Consumer Key" consumerSecret:#"Your Consumer Secret"] autorelease];
[twitterAPI verifyCredentialsWithSuccessBlock:^(NSString *username) {
[twitterAPI getUserTimelineWithScreenName:#"your ScreenName" count:25 successBlock:^(NSArray *statuses) {
NSLog(#"Success:%#", statuses);
} errorBlock:^(NSError *error){
NSLog(#"Error : %#",error.description);
}];
} errorBlock:^(NSError *error) {
NSLog(#"Error : %#",error.description);
}];
Verify that you have enter Consumer key and Consumer Secret in both plist and header prefix...
The code you posted has several issues. First, you're making a request from the verify method error block instead of the success block. Second, you're using the postResource method directly, instead of the higher level one to do what you want.
If all that you want is a bearer token for your consumer tokens, you can just copy / paste the sample code from STTwitter README in the App Only Authentication section.

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 !
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);
}];
I am Nicolas Seriot the creator of STTwitter.
The issue you encountered was a bug and I just fixed it.
Try to add HTML encode the keywords. For example with
[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

Resources