GithubHelp home page GithubHelp logo

twitterapi's Introduction

LOGO

BADGE_VERSION Join the chat at https://gitter.im/geduldig/TwitterAPI

TwitterAPI is a Python package for accessing Twitter's REST APIs and Streaming APIs. It supports OAuth 1.0 and OAuth 2.0 authentication. And, it works with the latest Python versions in both 2.x and 3.x branches.

Installation

From the command line:

pip install TwitterAPI

Documentation

Some Code...

[See TwitterAPI/examples for working examples.]

First, authenticate with your application credentials:

from TwitterAPI import TwitterAPI
api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

Tweet something:

r = api.request('statuses/update', {'status':'This is a tweet!'})
print(r.status_code)

Get tweet by its id:

r = api.request('statuses/show/:%d' % 210462857140252672)
print(r.text)

Get some tweets:

r = api.request('search/tweets', {'q':'pizza'})
for item in r:
        print(item)

Stream tweets from New York City:

r = api.request('statuses/filter', {'locations':'-74,40,-73,41'})
for item in r:
        print(item)

Notice that request() works with all endpoints found in either the REST APIs or the Streaming APIs. Usually request() takes two arguments: a Twitter endpoint and a dictionary of endpoint parameters. The above examples use get_iterator() to consume each tweet object. The iterator knows how to iterate results returned from either the REST APIs or the Streaming APIs.

You also have access to the response object returned by request(). From a response object r you can get the raw response with r.text and the HTTP status code with r.status_code. See the requests library documentation for more details.

Extra Goodies

Command-Line Utility (examples/cli)

twitterapi's People

Contributors

aronwc avatar biancini avatar dbuendiab avatar geduldig avatar gitter-badger avatar jeffnappi avatar jonasgeduldig avatar karlicoss avatar leogregianin avatar marviel avatar neilcturner avatar ravinewaters avatar rickredsix avatar tangentmonger avatar torufurukawa avatar

Watchers

 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.