Giter Club home page Giter Club logo

aftweetfetcher's Introduction

AFTweetFetcher

Simple class for retrieving tweets from twitter using their new 1.1 API without requiring the user to authenticate or have a twitter account stored on their device. I felt that accessing the most recent public tweets made by a given account should not require the user to have their credentials stored but as of the v1.1 API some authentication is required even for basic requests. This class allows you to authenticate at an application level rather than a user level. You can read about application-level authentication here: https://dev.twitter.com/docs/auth/application-only-auth

Requirements

This class currently only supports iOS 5.0 and up because it leverages changes made to NSURLConnection in iOS 5.0. Support for older versions of iOS could be added in the future using ASIHTTPRequest.

This class requires you to have an application registered with twitter. When viewing your application in twitter's developer area you should see the following information (blacked out for this example):

screenshot of twitter control panel showing consumer key

Take note of your Consumer key and Consumer secret, they will serve as your authentication for accessing the twitter API.

Example Use

Here is the most basic usage using the block syntax to retrieve a single tweet.

NSString *myConsumerKey = @""; //set this to your consumer key from twitter
NSString *myConsumerSecret = @""; //set this to your consumer secret from twitter
[AFTweetFetcher setConsumerKey:myConsumerKey andConsumerSecret:myConsumerSecret];
[AFTweetFetcher getMostRecentTweetFor:@"NASA" then:^(*AFTweet tweet){
//do whatever you'd like to do with the tweet here.
    NSLog(@"%@ - %@ on %@", tweet.text, tweet.author, tweet.postDate);
}];

You can also retrieve multiple tweets at once:

NSString *myConsumerKey = @""; //set this to your consumer key from twitter
NSString *myConsumerSecret = @""; //set this to your consumer secret from twitter
[AFTweetFetcher setConsumerKey:myConsumerKey andConsumerSecret:myConsumerSecret];
[AFTweetFetcher get:3 mostRecentTweetsFor:@"NASA" then:^(*NSArray tweets){
//do whatever you'd like to do with the tweets here.
    NSLog(@"%@", tweets);
}];

You can also use a delegate instead of the block syntax:

NSString *myConsumerKey = @""; //set this to your consumer key from twitter
NSString *myConsumerSecret = @""; //set this to your consumer secret from twitter
[AFTweetFetcher setConsumerKey:myConsumerKey andConsumerSecret:myConsumerSecret];
[AFTweetFetcher setDelegate:self];
[AFTweetFetcher get:3 mostRecentTweetsFor:@"NASA"]; //block not required

AFTweet Properties

The AFTweet object that is returned by calls to retrieve tweets has the following readonly public properties:

  • text (an NSString containing the full text of the tweet)
  • postDate (an NSDate representing the date and time the tweet as posted)
  • account (an NSString containing the account name)
  • permalink (an NSURL pointing at the tweet)
  • mediaURL (an NSURL pointing at any media attached to the tweet)
  • idNumber (an NSString representing the tweet's unique ID number)

The full dictionary parsed from the JSON returned by twitter is also available in case one of these convenience properties doesn't meet your requirements.

  • fullDictionary (an NSDictionary created from the JSON returned by twitter)

aftweetfetcher's People

Contributors

austinfitzpatrick avatar

Stargazers

blazr avatar  avatar Douglas Fischer avatar  avatar Ross Beale avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.