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

Overview

STTwitter

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

Like a FOSS version of Twitter Fabric TwitterKit, without the UI parts but with much more flexibility

Also includes a powerful Twitter dev console for OS X

[2015-03-28] Signed build of OS X demo app: STTwitterDemoOSX.app.zip
[2014-06-18] Swifter, A Twitter framework for iOS & OS X written in Swift, by @MatthewDonnelly
[2014-05-31] Follow STTwitter on Twitter: @STTLibrary
[2014-05-22] STTwitter was presented at CocoaHeads Lausanne (slides)
[2013-10-24] STTwitter was presented at SoftShake 2013 (slides).

Build Status

  1. Testimonials
  2. Installation
  3. Code Snippets
  4. Various Kinds of OAuth Connections
  5. Twitter Digits
  6. OAuth Consumer Tokens
  7. Demo / Test Project
  8. Integration Tips
  9. Troubleshooting
  10. Developers
  11. BSD 3-Clause License

Testimonials

"We are now using STTwitter" Adium developers

"An awesome Objective-C wrapper for Twitter’s HTTP API? Yes please!" @nilsou

"Your Library is really great, I stopped the development of my client because I was hating twitter APIs for some reasons, this Library make me want to continue, seriously thank you!" MP0w

"Powered by his own backend wrapper for HTTP calls, STTwitter writes most of the code for you for oAuth based authentication and API resource access like statuses, mentions, users, searches, friends & followers, favorites, lists, places, trends. The documentation is also excellent." STTwitter - Delightful Twitter Library for iOS / buddingdevelopers.com

Starting using STTwitter on a project. It is absolutely amazing. So easy to use. Thanks @nst021 @iOSDevZone

"I'm using this library for a WatchKit app and it works fantastically." inb4ohnoes

"I love STTwitter - it made things a breeze when building @entourageio" @_jeffreyjackson

Installation

Drag and drop STTwitter directory into your project.

Link your project with the following frameworks:

  • Accounts.framework
  • Social.framework
  • Twitter.framework (iOS only)
  • Security.framework (OS X only)

If you want to use CocoaPods, add the following two lines to your Podfile:

pod 'STTwitter'

Then, run the following command to install the STTwitter pod:

pod install

STTwitter does not depend on AppKit or UIKit and hence can be used in a command-line Twitter client.

STTwitter <= 0.2.2 requires iOS 5+ or OS X 10.7+.

STTwitter >= 0.2.3 requires iOS 7+ or OS X 10.9+.

Vea Software has a great live-demo tutorial about creating a simple iOS app using STTwitter's app only mode.

Code Snippets

Here are several ways to use STTwitter.

You'll find complete, minimal, command-line projects in the demo_cli directory:

  • streaming use the streaming API to filter all tweets with some word
  • streaming_with_bot same as above, but reply instantly from another account
  • reverse_auth perform reverse authentication
  • followers display your followers by following Twitter's API cursors, and waiting for a while before reaching rate limits
  • favorites display tweets favorited by people you follow, set a tweet's favorite status
  • conversation post several tweets in the same conversation
  • t2rss convert your timeline into an RSS feed
Instantiate STTwitterAPI
STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:@""
                                                      consumerSecret:@""
                                                            username:@""
                                                            password:@""];
Verify the credentials
[twitter verifyCredentialsWithUserSuccessBlock:^(NSString *username, NSString *userID) {
    // ...
} errorBlock:^(NSError *error) {
    // ...
}];
Get the timeline statuses
[twitter getHomeTimelineSinceID:nil
                          count:100
                   successBlock:^(NSArray *statuses) {
    // ...
} errorBlock:^(NSError *error) {
    // ...
}];
Streaming API
NSObject <STTwitterRequestProtocol> *request = [twitter getStatusesSampleDelimited:nil
                                                                     stallWarnings:nil
                                                                     progressBlock:^(id response) {
    // ...
} stallWarningBlock:nil
         errorBlock:^(NSError *error) {
    // ...
}];

// ...

[request cancel]; // when you're done with it
App Only Authentication
STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@""
                                                        consumerSecret:@""];

[twitter verifyCredentialsWithUserSuccessBlock:^(NSString *username, NSString *userID) {

    [twitter getUserTimelineWithScreenName:@"barackobama"
                              successBlock:^(NSArray *statuses) {
        // ...
    } errorBlock:^(NSError *error) {
        // ...
    }];

} errorBlock:^(NSError *error) {
    // ...
}];
Enumerate results with cursors, pause according to rate limits
[_twitter fetchAndFollowCursorsForResource:@"followers/ids.json"
                                HTTPMethod:@"GET"
                             baseURLString:@"https://api.twitter.com/1.1"
                                parameters:@{@"screen_name":@"0xcharlie"}
                       uploadProgressBlock:nil
                     downloadProgressBlock:nil
                              successBlock:^(id request, NSDictionary *requestHeaders, NSDictionary *responseHeaders, id response, BOOL morePagesToCome, BOOL *stop) {
    NSLog(@"-- success, more to come: %d, %@", morePagesToCome, response);
} pauseBlock:^(NSDate *nextRequestDate) {
    NSLog(@"-- rate limit exhausted, nextRequestDate: %@", nextRequestDate);
} errorBlock:^(id request, NSDictionary *requestHeaders, NSDictionary *responseHeaders, NSError *error) {
    NSLog(@"-- %@", error);
}];

Various Kinds of OAuth Connections

You can instantiate STTwitterAPI in three ways:

  • use the Twitter account set in OS X Preferences or iOS Settings
  • use a custom consumer key and consumer secret (four flavors)
    • get an URL, fetch a PIN, enter it in your app, get oauth access tokens
    • set username and password, get oauth access tokens with XAuth, if the app is entitled to
    • set oauth token and oauth token secret directly
    • open Safari (or a UIWebView instance if you prefer), authenticate on Twitter and receive access tokens in your app through a custom URL scheme
  • use the Application Only authentication and get / use a "bearer token"

So there are five cases altogether, hence these five methods:

+ (STTwitterAPI *)twitterAPIOSWithFirstAccount;

+ (STTwitterAPI *)twitterAPIWithOAuthConsumerKey:(NSString *)consumerKey
                                  consumerSecret:(NSString *)consumerSecret;

+ (STTwitterAPI *)twitterAPIWithOAuthConsumerKey:(NSString *)consumerKey
                                  consumerSecret:(NSString *)consumerSecret
                                        username:(NSString *)username
                                        password:(NSString *)password;

+ (STTwitterAPI *)twitterAPIWithOAuthConsumerKey:(NSString *)consumerKey
                                  consumerSecret:(NSString *)consumerSecret
                                      oauthToken:(NSString *)oauthToken
                                oauthTokenSecret:(NSString *)oauthTokenSecret;

+ (STTwitterAPI *)twitterAPIAppOnlyWithConsumerKey:(NSString *)consumerKey
                                    consumerSecret:(NSString *)consumerSecret;
Callbacks URLs

After authenticating in Safari or in a web view, Twitter redirects to the callback URL with some additional parameters. (Your Twitter app' settings MUST allow the usage of callbacks by specifying a dummy URL, such as http://www.cnn.com. This URL is then overriden by the oauthCallback parameter in:

- (void)postTokenRequest:(void(^)(NSURL *url, NSString *oauthToken))successBlock
authenticateInsteadOfAuthorize:(BOOL)authenticateInsteadOfAuthorize
              forceLogin:(NSNumber *)forceLogin
              screenName:(NSString *)screenName
           oauthCallback:(NSString *)oauthCallback
              errorBlock:(void(^)(NSError *error))errorBlock;

STTwitter Twitter App Settings

Reverse Authentication

Reference: https://dev.twitter.com/docs/ios/using-reverse-auth

The most common use case of reverse authentication is letting users register/login to a remote service with their OS X or iOS Twitter account.

iOS/OSX     Twitter     Server
-------------->                 reverse auth.
< - - - - - - -                 access tokens

----------------------------->  access tokens

               <--------------  access Twitter on user's behalf
                - - - - - - ->

Here is how to use reverse authentication with STTwitter:

STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerName:nil
                                                          consumerKey:@"CONSUMER_KEY"
                                                       consumerSecret:@"CONSUMER_SECRET"];

[twitter postReverseOAuthTokenRequest:^(NSString *authenticationHeader) {

    STTwitterAPI *twitterAPIOS = [STTwitterAPI twitterAPIOSWithFirstAccount];

    [twitterAPIOS verifyCredentialsWithUserSuccessBlock:^(NSString *username, NSString *userID) {

        [twitterAPIOS postReverseAuthAccessTokenWithAuthenticationHeader:authenticationHeader
                                                            successBlock:^(NSString *oAuthToken,
                                                                           NSString *oAuthTokenSecret,
                                                                           NSString *userID,
                                                                           NSString *screenName) {

                                                                // use the tokens...

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

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

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

Contrary to what can be read here and there, you can perfectly access direct messages from iOS Twitter accounts.

Twitter Digits

https://docs.fabric.io/ios/digits/digits.html

In this flow, you start with consumer tokens and app only mode, and end up with access tokens, after verifying a phone number with a PIN sent by SMS.

It goes like this:

1. start with consumer tokens
2. get a bearer token (ie. app only mode)
2. get a guest token, (ie. temporary user id)
3. post a phone number, using the guest token
4. post the received PIN code for the phone number, using the guest token
5. receive access tokens in return

See a working example in STAuthenticationVC.m.

OAuth Consumer Tokens

In Twitter REST API v1.1, each client application must authenticate itself with consumer key and consumer secret tokens. You can request consumer tokens for your app on Twitter's website: https://apps.twitter.com/.

STTwitter demo project comes with TwitterClients.plist where you can enter your own consumer tokens.

Demo / Test Project

There is a demo project for OS X in demo_osx, which lets you choose how to get the OAuth tokens (see below).

An archive generated on 2013-10-20 10:35 is available at http://seriot.ch/temp/STTwitterDemoOSX.app.zip.

Once you got the OAuth tokens, you can get your timeline and post a new status.

There is also a simple iOS demo project in demo_ios.

STTwitter Demo iOS STTwitter Demo iOS sample tweet

Integration Tips

Concurrency

STTwitter is supposed to be used from the main thread. The HTTP requests are performed anychronously and the callbacks are guaranteed to be called on main thread.

Credentials verification

There's no need to verify the credentials before each request.

Doing so when the application starts and when the application enters foreground sounds reasonable, though.

Timeout

Unless told otherwise, STTwitter will use the underling classes default timeouts.

You can also set the timeout by yourself:

[twitter setTimeoutInSeconds:5.0];
Remove Asserts in Release Mode

There are several asserts in the code. They are very useful in debug mode but you should not include them in release.

New projects created with Xcode 5 already remove NSAssert logic by default in release.

In older projects, you can set the compilation flag -DNS_BLOCK_ASSERTIONS=1.

Number of Characters in a Tweet

Use the method -[NSString st_numberOfCharactersInATweet] to let the user know how many characters she can enter before the end of the Tweet. The method may also return a negative value if the string exceeds a tweet's maximum length. The method considers the shortened URL lengths.

Date Formatter

In order to convert the string in the created_at field from Twitter's JSON into an NSDate instance, you can use the +[NSDateFormatter st_TwitterDateFormatter].

NSDateFormatter *df = [NSDateFormatter st_TwitterDateFormatter];
NSString *dateString = [d valueForKey:@"created_at"]; // "Sun Jun 28 20:33:01 +0000 2009"
NSDate *date = [df dateFromString:dateString];
URLs Shorteners

In order to expand shortened URLs such as Twitter's t.co service, use:

[STHTTPRequest expandedURLStringForShortenedURLString:@"http://t.co/tmoxbSfDWc" successBlock:^(NSString *expandedURLString) {
    //
} errorBlock:^(NSError *error) {
    //
}];
API Responses Text Processing

You may want to use Twitter's own Objective-C library for text processing: https://github.com/twitter/twitter-text-objc/.

twitter-text-objc provides you with methods such as:

+ (NSArray*)entitiesInText:(NSString*)text;
+ (NSArray*)URLsInText:(NSString*)text;
+ (NSArray*)hashtagsInText:(NSString*)text checkingURLOverlap:(BOOL)checkingURLOverlap;
+ (NSArray*)symbolsInText:(NSString*)text checkingURLOverlap:(BOOL)checkingURLOverlap;
+ (NSArray*)mentionedScreenNamesInText:(NSString*)text;
+ (NSArray*)mentionsOrListsInText:(NSString*)text;
+ (TwitterTextEntity*)repliedScreenNameInText:(NSString*)text;
Logout

The correct approach to logout a user is setting the STTwitterAPI instance to nil.

You'll create a new one at the next login.

Boolean Parameters

There are a lot of optional parameters in Twitter API. In STTwitter, you can ignore such parameters by passing nil. Regarding boolean parameters, STTwitter can't just use Objective-C YES and NO because NO has the same value as nil (zero). So boolean parameters are wrapped into NSNumber objects, which are pretty easy to use with boolean values thanks to Objective-C literals. So, with STTwitter, you will assign an optional parameter of Twitter API either as @(YES), @(NO) or nil.

Long Methods

STTwitter provides a full, "one-to-one" Objective-C front-end to Twitter REST API. It often results in long method names with many parameters. In your application, you may want to add your own, simplified methods on top of STTwitterAPI. A good idea is to create an Objective-C category for your application, such as in the following code.

STTwitterAPI+MyApp.h

#import "STTwitterAPI.h"

@interface STTwitterAPI (MyApp)

- (void)getStatusesShowID:(NSString *)statusID
             successBlock:(void(^)(NSDictionary *status))successBlock
               errorBlock:(void(^)(NSError *error))errorBlock;

@end

STTwitterAPI+MyApp.m

#import "STTwitterAPI+MyApp.h"

@implementation STTwitterAPI (MyApp)

- (void)getStatusesShowID:(NSString *)statusID
             successBlock:(void(^)(NSDictionary *status))successBlock
               errorBlock:(void(^)(NSError *error))errorBlock {

    [self getStatusesShowID:statusID
                   trimUser:@(YES)
           includeMyRetweet:nil
            includeEntities:@(NO)
               successBlock:^(NSDictionary *status) {

                   successBlock(status);

               } errorBlock:^(NSError *error) {

                   errorBlock(error);

               }];
}

@end
Stream Request and Connection Losses

Streaming requests may be lost when your iOS application comes back to foreground after a while in background. In order to handle this case properly, you can detect the connection loss in the error block and restart the stream request from there.

// ...
} errorBlock:^(NSError *error) {

    if([[error domain] isEqualToString:NSURLErrorDomain] && [error code] == NSURLErrorNetworkConnectionLost) {
        [self startStreamRequest];
    }

}];

Troubleshooting

xAuth

Twitter restricts the xAuth authentication process to xAuth-enabled consumer tokens only. So, if you get an error like The consumer tokens are probably not xAuth enabled. while accessing https://api.twitter.com/oauth/access_token, see Twitter's website https://dev.twitter.com/docs/oauth/xauth and ask Twitter to enable the xAuth authentication process for your consumer tokens.

Anything Else

Please fill an issue on GitHub or use the STTwitter tag on StackOverflow.

Developers

The application only interacts with STTwitterAPI.

STTwitterAPI maps Objective-C methods with all Twitter API endpoints.

You can create your own convenience methods with fewer parameters. You can also use this generic method directly:

  - (id)fetchResource:(NSString *)resource
           HTTPMethod:(NSString *)HTTPMethod
        baseURLString:(NSString *)baseURLString
           parameters:(NSDictionary *)params
  uploadProgressBlock:(void(^)(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite))uploadProgressBlock
downloadProgressBlock:(void(^)(NSObject<STTwitterRequestProtocol> *request, id response))downloadProgressBlock
         successBlock:(void(^)(NSObject<STTwitterRequestProtocol> *request, NSDictionary *requestHeaders, NSDictionary *responseHeaders, id response))successBlock
           errorBlock:(void(^)(NSObject<STTwitterRequestProtocol> *request, NSDictionary *requestHeaders, NSDictionary *responseHeaders, NSError *error))errorBlock;
Layer Model
 +------------------------------------------------------------------------+
 |                         Your Application                               |
 +--------------------------------------------------------+---------------+
 |                  STTwitterAPI                          | STTwitterHTML |
 +--------------------------------------------------------+               |
 + - - - - - - - - - - - - - - - - - - - - - - - - - - - -+               |
 |              STTwitterOAuthProtocol                    |               |
 + - - - - - - - - - - - - - - - - - - - - - - - - - - - -+               |
 +--------------------+----------------+------------------+               |
 |    STTwitterOS     | STTwitterOAuth | STTwitterAppOnly |               |
 +--------------------+----------------+------------------+---------------+
 | STTwitterOSRequest |                   STHTTPRequest                   |
 +--------------------+---------------------------------------------------+
  |
  + Accounts.framework
  + Social.framework
Summary
 * STTwitterAPI
    - can be instantiated with the authentication mode you want
    - provides methods to interact with each Twitter API endpoint

 * STTwitterHTML
    - a hackish class to login on Twitter by parsing the HTML code and get a PIN
    - it can break at anytime, your app should not rely on it in production

 * STTwitterOAuthProtocol
    - provides generic methods to POST and GET resources on Twitter's hosts

 * STTwitterOS
    - uses Twitter accounts defined in OS X Preferences or iOS Settings
    - uses OS X / iOS frameworks to interact with Twitter API

 * STTwitterOSRequest
    - block-based wrapper around SLRequest's underlying NSURLRequest
    
 * STTwitterOAuth
    - implements OAuth and xAuth authentication

 * STTwitterAppOnly
    - implements the 'app only' authentication
    - https://dev.twitter.com/oauth/application-only

 * STHTTPRequest
    - block-based wrapper around NSURLConnection
    - https://github.com/nst/STHTTPRequest

BSD 3-Clause License

See LICENCE.txt.

Comments
  • STTwitter Not Returning Anything Neither Success or Error

    STTwitter Not Returning Anything Neither Success or Error

    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. STTwitter Not Returning Anything Neither Success or Error and the app continue executing the rest of code. Anybody know what's wrong ?

    bug 
    opened by WorlDroid 12
  • HTTP Status 401: Unauthorized

    HTTP Status 401: Unauthorized

    I am running the STTwitterDemoiOS project provide. I replaced the key and secret in the project with my new keys.

    When I try to login with Safari, the app returns an error message

    "-- error: Error Domain=STHTTPRequest Code=401 "HTTP Status 401: Unauthorized" UserInfo=0xa4790a0 {NSLocalizedDescription=HTTP Status 401: Unauthorized} "

    I have tried changing the Keys by revoking the previous ones. My app on twitter has "Read, write, and direct messages" permissions. Also "Sign in with Twitter" is set to "Yes".

    I am building the app with Xcode 5.1 on iPhone 5S(iOS 7.0.4)

    Help me in getting rid of this message.

    Regards, Naresh

    opened by NareshKalakuntla 12
  • Nothing Happens

    Nothing Happens

    Hello, I have one place where the postStatus actually works, however I have another place in my project where I do not get a response, neither success or do I get an error. What should I do?

    question 
    opened by stevo2105 10
  • Correct useage ?

    Correct useage ?

    Is this the correct useage to verify my own app ?

    it is all working correctly but the view this is in does not dealloc while this code is run

    My project is ARC but I always log out the dealloc method to see if it is cleaning up ok

    If I enter / exit this view with just the code below the memory keeps increasing

    // self.twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:kTwitterAPI consumerSecret:kTwitterSECRET]; [_twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) { NSLog(@"Access granted with %@", bearerToken); } errorBlock:^(NSError *error) { NSLog(@"-- error %@", error); }];

    opened by acegames 10
  • Cannot use stream API

    Cannot use stream API

    Hi, today I'm trying to use your library. Everything works fine, except stream api. Here is my code:

    NSLog(@"hashtag: %@",hashTag);
    
    //-build twitter api object here
    
    NSString *authDataStr = [[NSUserDefaults standardUserDefaults] objectForKey:Twitter_OAuth_Data];
    NSArray *subAuthDataStrs = [authDataStr componentsSeparatedByString:@"&"];
    NSString *oauthToken = [[[subAuthDataStrs objectAtIndex:0] componentsSeparatedByString:@"="] objectAtIndex:1];
    NSString *oauthTokenSecret = [[[subAuthDataStrs objectAtIndex:1] componentsSeparatedByString:@"="] objectAtIndex:1];
    
    STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:kOAuthConsumerKey
                                                          consumerSecret:kOAuthConsumerSecret
                                                              oauthToken:oauthToken
                                                        oauthTokenSecret:oauthTokenSecret];
    
    [twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
    
        NSLog(@"username: %@",username);
    
        [twitter postStatusesFilterUserIDs:nil
                           keywordsToTrack:@[@"#MEForum"]
                     locationBoundingBoxes:nil
                                 delimited:nil
                             stallWarnings:nil
                             progressBlock:^(id response) {
                                    NSLog(@"progressBlock: %@",response);
                             }
                         stallWarningBlock:^(NSString *code, NSString *message, NSUInteger percentFull) {
                                    NSLog(@"-- stall warning");
                            }
                                errorBlock:^(NSError *error) {
                                    NSLog(@"-- %@", [error localizedDescription]);
                                    if([[error domain] isEqualToString:NSURLErrorDomain] && [error code] == NSURLErrorNetworkConnectionLost) {
                }
            }
        ];
    
    } errorBlock:^(NSError *error) {
        NSLog(@"Error here: %@", error.description);
    }];
    

    The credentials work for other functions but for streaming, it always return error: HTTP Status 401: Unauthorized Actually, it logs username correctly. Something must be wrong here.

    opened by lenhhoxung86 9
  • Setting includeReplies to nil fails in user streams

    Setting includeReplies to nil fails in user streams

    I'm calling

    [api getUserStreamDelimited:@NO stallWarnings:@YES includeMessagesFromFollowedAccounts:nil includeReplies:nil keywordsToTrack:nil locationBoundingBoxes:nil progressBlock:progressBlock stallWarningBlock:stallWarningBlock errorBlock:errorBlock];
    

    and it returns a timeout error. I might be mistaken but isn't setting includeReplies to nil supposed to return only mutual follow replies as described in the Streaming API docs?

    opened by inb4ohnoes 9
  • CocoaPods compatibility

    CocoaPods compatibility

    Hi,

    I was going to use STTwitter in a project that I've already set up with CocoaPods (http://cocoapods.org/) and noticed that you don't have a pod set up, so I went ahead and created a podspec for it. I have it hosted as a private gist currently, but if you have interest in making STTwitter available as a pod for everyone to use I can submit it to CocoaPods and they would host the podspec file. That way, it'd be as easy as including 'pod STTwitter' in a project using CocoaPods to utilize it.

    Here's the gist, it's only really missing any additional author(s) besides yourself (as well as email addresses, if you want them included), and supported OS X versions:

    https://gist.github.com/eroth/573f80056acf53f4dbca/raw/9ef10dc0ff4dd54ba81e3c3110ca6a44a57971f6/STTwitter.podspec

    Cheers!

    opened by eroth 9
  • STTwitter Object is nil when Making Rootview controller  and pushing it

    STTwitter Object is nil when Making Rootview controller and pushing it

    Everything works perfect in STTwitter Demo App . I have checked with replacing my Consumer key and my consumer Secret key

    - (IBAction)loginWithTwitter:(id)sender
    {
        _twitter= [STTwitterAPI twitterAPIWithOAuthConsumerKey:@"My Consumer Key"
                                                     consumerSecret:@"My Consumer secret Key"];
    
    
        [_twitter postTokenRequest:^(NSURL *url, NSString *oauthToken) {
            NSLog(@"-- url: %@", url);
            NSLog(@"-- oauthToken: %@", oauthToken);
    
            [[UIApplication sharedApplication] openURL:url];
            WebViewVC *webViewVC = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewVC"];
    
            [self presentViewController:webViewVC animated:YES completion:^{
                NSURLRequest *requestTwiterURL = [NSURLRequest requestWithURL:url];
                [webViewVC.webView loadRequest:requestTwiterURL];
            }];
    
    
        } authenticateInsteadOfAuthorize:NO
                        forceLogin:@(YES)
                        screenName:nil
                     oauthCallback:@"myapp://ascratech.com/"
                        errorBlock:^(NSError *error) {
                            NSLog(@"-- error: %@", error);
                        }];
    
    }
    
    - (void)setOAuthToken:(NSString *)token oauthVerifier:(NSString *)verifier
    {
        [self dismissViewControllerAnimated:YES completion:^{
    
        }];
    
        [self.twitter postAccessTokenRequestWithPIN:verifier successBlock:^(NSString *oauthToken, NSString *oauthTokenSecret, NSString *userID, NSString *screenName) {
            NSLog(@"-- screenName: %@", screenName);
            NSLog(@"-- userID: %@", userID);
            NSLog(@"-- oauthToken: %@", oauthToken);
            NSLog(@"-- oauthTokenSecret: %@", oauthTokenSecret);
    
    
    
            [self.twitter getUserInformationFor:screenName successBlock:^(NSDictionary *user) {
                NSLog(@"-- user info : %@", user);
    
    
            } errorBlock:^(NSError *error) {
                NSLog(@"-- error: %@", error);
            }];
    
          } errorBlock:^(NSError *error) {
    
            NSLog(@"-- %@", [error localizedDescription]);
        }];
    }
    
    
    -(BOOL)application:(UIApplication *)application
               openURL:(NSURL *)url
     sourceApplication:(NSString *)sourceApplication
            annotation:(id)annotation
    {
    
     if ([[url scheme] isEqualToString:@"myapp"] )
        {
            NSDictionary *d = [self parametersDictionaryFromQueryString:[url query]];
            NSString *token = d[@"oauth_token"];
            NSString *verifier = d[@"oauth_verifier"];
             CGSize iOSScreenSize=[[UIScreen mainScreen]bounds].size;
    
    if(iOSScreenSize.height==568)
            {
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iphone5" bundle: nil];
                WelcomeViewController   *WelcomeVC = [storyboard   instantiateViewControllerWithIdentifier:@"WelcomeViewController"];
                            [(UINavigationController *)self.window.rootViewController pushViewController:WelcomeVC animated:YES];
                 [WelcomeVC setOAuthToken:token oauth Verifier:verifier];
            }
    return yes;
    }
    

    Please help me out . I have attached your code screen shot and My code as well . I have circled things which are not same. betwen yours and mine

    this is my Login page screen shot 2015-04-09 at 6 35 53 pm

    this screen shot is from your demo app

    screen shot 2015-04-09 at 6 43 06 pm

    this screen shot is from my app

    screen shot 2015-04-09 at 6 43 54 pm

    question 
    opened by sunny45 8
  • Not able to login once logged out.

    Not able to login once logged out.

    I have implemented STTwitter in my application which uses many API's of the twitter. STTwitter was so easy to implement. Thanks guys for saving my time. But, now I have an issue. Am able to login, use every API. But after I logout, Am not able to login the next time. HTTP unauthorized error. While logouting I cleared the STTwitterAPI instance to nil. Still its not working. Please help me.

    opened by abingeorgev 8
  • oAuth  Authentication.  regexError: Can't find a match for regex: <error>(.*)</error>

    oAuth Authentication. regexError: Can't find a match for regex: (.*)

    Hi. I'm need use stream API for this propose oAuth authentication require. I'm trying implement some Reverse Authentication from example but it back error. regexError: Can't find a match for regex: (.*) Can you suggest me what it error mean ? Authentication with pin and App Only Authentication don't work for me too, it back Error 401 Unauthorized. Exist example project STTwitter for Xcode 4.5?

    opened by holdyar 8
  • Request: Ability to determine if stream is active

    Request: Ability to determine if stream is active

    It would be awesome if we could tell if a stream is active or not outside of using stall warnings. I apologize if this functionality already exists but I didn't find anything for it.

    opened by inb4ohnoes 8
  • Thread 1:

    Thread 1: "-[STTwitterAppOnly postTokenRequest:authenticateInsteadOfAuthorize:forceLogin:screenName:oauthCallback:errorBlock:]: unrecognized selector sent to instance 0x280371140"

     - (IBAction)loginOnTheWebAction:(id)sender {
          
        self.twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:_consumerKeyTextField.text consumerSecret:_consumerSecretTextField.text];
     
        _loginStatusLabel.text = @"Trying to login with Safari...";
        _loginStatusLabel.text = @"";
     
        [self.twitter postTokenRequest:^(NSURL *url, NSString *oauthToken) {
            NSLog(@"-- url: %@", url);
            NSLog(@"-- oauthToken: %@", oauthToken);
            
            if([self.openSafariSwitch isOn]) {
                [[UIApplication sharedApplication] openURL:url];
            } else {
                WebViewVC *webViewVC = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewVC"];
                
                [self presentViewController:webViewVC animated:YES completion:^{
                    NSURLRequest *request = [NSURLRequest requestWithURL:url];
                    [webViewVC.webView loadRequest:request];
                }];
            }
            
        } authenticateInsteadOfAuthorize:NO
                        forceLogin:@(YES)
                        screenName:nil //scheme://
                     oauthCallback:@"STTwitterDemoIOS://"
                        errorBlock:^(NSError *error) {
                            NSLog(@"-- error: %@", error);
                            _loginStatusLabel.text = [error localizedDescription];
                        }];
    }
    
    
    opened by hw20101101 1
  • Twitter API 2.0

    Twitter API 2.0

    So, after so many years, Twitter API 2.0 finally comes. https://twittercommunity.com/t/new-conversation-id-field-and-operator-makes-it-possible-to-easily-retrieve-complete-conversation-threads/139613

    Maybe it's time we bring back life to this great project?

    opened by xiao99xiao 0
  • Fixes to remove warnings after updating project to recommended settings

    Fixes to remove warnings after updating project to recommended settings

    After updating the to the latest iOS11 recommended XCode project settings there are a number of warnings. This PR just cleans up the warnings so that the STTwitter source compiles without any warnings.

    opened by W0VOS 2
  • ⚠️ Legacy APIs must be migrated to new ones within 5 months!

    ⚠️ Legacy APIs must be migrated to new ones within 5 months!

    Twitter is turning off many legacy APIs, including:

    User Streams Site Streams GET direct_messages GET direct_messages/sent GET direct_messages/show POST direct_messages/destroy

    STTwitter should be updated to take advantage of the new set of APIs by June 19th. Otherwise existing endpoints this library provides will become broken. If STTwitter will not be updated, I believe this library should be marked "unsupported"...

    enhancement 
    opened by inb4ohnoes 2
  • newest XCode throws warnings: This block declaration is not a prototype

    newest XCode throws warnings: This block declaration is not a prototype

    Hi,

    thanks for the STTwitter library. I got some warnings This block declaration is not a prototype for the library in a desktop project, I think it started with XCode 9.2. Most of them are easily to patch by applying the void in the empty declaration but some are not so easy to fix. I could provide my humble corrections in a pull request...

    opened by HerrSteiner 0
Owner
Nicolas Seriot
T24gdGhlIEludGVybmV0LCBub2JvZHkga25vd3MgeW91J3JlIGEgZnJpZGdlLg==
Nicolas Seriot
The Easiest and Simplest iOS library for Twitter and Facebook. Just Drop in and Use!

EasySocial iOS Library for Twitter and Facebook This library allows your apps to use Twitter and Facebook with minimal understanding of the relevant S

pj 124 Nov 17, 2022
Giphy API client for iOS in Objective-C

Giphy-iOS Giphy-iOS is a Giphy API client for iOS in Objective-C. Usage To run the example project, clone the repo, and run pod install from the Examp

alex choi 52 Jul 11, 2019
An easy-to-use Objective-C wrapper for the Uber API (no longer supported)

UberKit UberKit is a simple Objective-C wrapper for the new Uber API . Installation Cocoapods UberKit is available through Cocoapods. To install it, s

Sachin Kesiraju 95 Jun 30, 2022
ObjectiveFlickr, a Flickr API framework for Objective-C

ObjectiveFlickr ObjectiveFlickr is a Flickr API framework designed for Mac and iPhone apps. OAuth Support ObjectiveFlickr now supports Flickr's new OA

Lukhnos Liu 714 Jan 9, 2023
A Twitter framework for iOS & OS X written in Swift

Getting Started Installation If you're using Xcode 6 and above, Swifter can be installed by simply dragging the Swifter Xcode project into your own pr

Matt Donnelly 2.4k Dec 30, 2022
Twitter Clone for iOS With Swift

Postwitter Date: December 1, 2021 Product Name: Postwitter Problem Statement: iO

Shohin Abdulkhamidov 3 Aug 16, 2022
A Dropbox v2 client library written in Objective-C

TJDropbox TJDropbox is a Dropbox v2 client library written in Objective-C. When Dropbox originally announced their v2 API they included only a Swift c

Tim Johnsen 61 Dec 21, 2022
An Elegant Spotify Web API Library Written in Swift for iOS and macOS

Written in Swift 4.2 Spartan is a lightweight, elegant, and easy to use Spotify Web API wrapper library for iOS and macOS written in Swift 3. Under th

Dalton Hinterscher 107 Nov 8, 2022
Unified API Library for: Cloud Storage, Social Log-In, Social Interaction, Payment, Email, SMS, POIs, Video & Messaging.

Unified API Library for: Cloud Storage, Social Log-In, Social Interaction, Payment, Email, SMS, POIs, Video & Messaging. Included services are Dropbox, Google Drive, OneDrive, OneDrive for Business, Box, Egnyte, PayPal, Stripe, Google Places, Foursquare, Yelp, YouTube, Vimeo, Twitch, Facebook Messenger, Telegram, Line, Viber, Facebook, GitHub, Google+, LinkedIn, Slack, Twitter, Windows Live, Yahoo, Mailjet, Sendgrid, Twilio, Nexmo, Twizo.

CloudRail 195 Nov 29, 2021
A Swift library for the Forecast.io Dark Sky API

Requirements To use ForecastIO, all you need is an API key for the Dark Sky API. ForecastIO supports iOS (≥9.0), macOS (≥10.10), watchOS (≥2.0), and t

Satyam Ghodasara 163 Jul 26, 2022
Easy and powerful way to interact with VK API for iOS and macOS

Easy and powerful way to interact with VK API for iOS and macOS. Key features ?? It's not ios-vk-sdk ?? ?? One library for iOS and mac OS ?? ?? Fully

null 260 Dec 22, 2022
A Swift wrapper for Foursquare API. iOS and OSX.

Das Quadrat Das Quadrat is Foursquare API wrapper written in Swift. Features Supports iOS and OSX. Covers all API endpoints. Authorization process imp

Constantine Fry 171 Jun 18, 2022
Unofficial Dribbble iOS wrapper allows you to integrate Dribble API into iOS application (Designer, Shot, Comment, User Story, Like, Follow)

DribbbleSDK DribbbleSDK is easy-to-use iOS wrapper for Dribbble SDK. We're working hard to complete the full coverage of available methods and make th

Agilie Team 74 Dec 2, 2020
Unofficial GitHub API client in Swift

Github.swift ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut

Khoa 184 Nov 25, 2022
A swift SDK for Medium's OAuth2 API

Medium SDK - Swift A library to allow access to Medium API for any Swift iOS application. Features Medium.com authorization & token handling Login sta

null 11 Jan 22, 2022
Swift Wrapper For Bittrex API

BittrexApiKit Swift client for Bittrex api. It support all APIs with most recent changes. more info here let api = Bittrex(apikey: "api key", secretke

Saeid 8 Apr 5, 2021
Instagram API client written in Swift

SwiftInstagram is a wrapper for the Instagram API written in Swift. It allows you to authenticate users and request data from Instagram effortlessly.

Ander Goig 579 Dec 31, 2022
A Slack API Client for the Perfect Server-Side Swift Framework

PerfectSlackAPIClient is an API Client to access the Slack API from your Perfect Server Side Swift application. It is build on top of PerfectAPIClient

Cap.雪ノ下八幡 2 Dec 1, 2019
An API wrapper for bitFlyer.

SwiftFlyer An API wrapper for bitFlyer that supports all providing API. API Document https://lightning.bitflyer.jp/docs Usage Public API Fetch a marke

Ryo Ishikawa 39 Nov 3, 2022