2011-05-10 4 views

答えて

6

はTweepyをお試しください:http://code.google.com/p/tweepy/

あなたは同じGoogle Codeのリンクでそれをtutorial wiki pageに取得することができます。 easy_installをして、それをインストールするには

、ただのgitでそれをインストールするにはeasy_install tweepy

を実行します。

tar xzvf tweepy-1.7.1.tar.gz 
cd tweepy-1.7.1 
python setup.py install 
:その後、何かを実行する http://pypi.python.org/pypi/tweepyからソースをダウンロードし、ソースからインストールするには

git clone git://github.com/joshthecoder/tweepy.git 
cd tweepy 
python setup.py install 

+0

偉大な、私はそれをインポートすることはできません!それ、どうやったら出来るの? –

+1

インストール手順が追加されました。インストールした後、 'import tweety'はうまくいくはずです。 – 146

+0

ありがとう:)テキストメイトのようなサードパーティ編集者のためにもこの作業はできますか? –

3

私は過去2〜3ヶ月間Python-Twitterを使用しています。 Twitter APIからのデータの取得やツイートの投稿が非常に簡単です。

あなたはPIPを介してインストールすることができる:

pip install python-twitter 

またはgitの=>https://github.com/bear/python-twitter.git 次いで(PIPを介して行うことができる)の依存 がREADME.rt

python setup.py build 
の指示に従っのインストールからのクローニングによっての

その後、

python setup.py install 

ライブラリをインストールしたら、単純な認証ファイルを設定することをお勧めします。 twitterAuth.py)

# twitterAuth.py 

import twitter 

"""This script is meant to connect to the Twitter API via the tokens below""" 

api = twitter.Api(consumer_key='yourConsumerKeyGoesHere', 
    consumer_secret='yourConsumerSecretGoesHere', 
    access_token_key='your-AccessTokenGoesHere', 
    access_token_secret='yourTokenSecretGoesHere') 

次に、Twitter APIにアクセスする必要のあるスクリプトからこれをインポートするだけです。

from twitter import * 
import twitterAuth 

api = twitterAuth.api 

status = api.PostUpdate('testing twitter-python') 
print status.text 
0

​​非常にユーザーフレンドリーTwitterのAPIである:ここでの記事さえずるという単純な例です。

+0

これは上記の答えと同じではありませんか? – Huey

1

Twitterはongoing list of librariesを管理しています。開発者は、Pythonを含む多くの言語で使用できます。正直なところ、最も簡単な方法は、Python requestsライブラリを使用して、多くのクライアントのうちの1つに単純なHTTP要求を実行することです。REST endpoints

ここ

は、私はTwitterのつぶやきは、エンドポイントをREST検索する書いた例です。

import requests 
from requests_oauthlib import OAuth1 # For authentication 

_consumer_key = <api_key> 
_consumer_secret = <api_secret> 
_key = <token> 
_secret = <token_secret> 

_auth = OAuth1(_consumer_key, _consumer_secret, _key, _secret) 

def search(search_terms): 
    # Twitter search URL: 
    url = 'https://api.twitter.com/1.1/search/tweets.json' 
    payload = { 
     'q': search_terms, # May be @user_search or #hash_search also 
     'lang': 'en', # Based on ISO 639-1 two-letter code 
     'result_type': 'mixed', 
     'count': '100', # Number of tweets to return per page, up to a max of 100 
     'until': Get_Time()['today'] 
    } 
    search_results = requests.get(url, auth=_auth, params=payload) 
    print search_results.json() # Gets the raw results in json format 

APIとトークンキーと秘密を作成するには、apps.twitter.comで、ここでアプリを作成する必要があります。 Twitterは非常にユーザーフレンドリーなREST APIとドキュメンテーションを持っているので、いくつかのHTTPリクエストを行い、適切な応答を受け取ると理解しやすくなると思います。

関連する問題