Twitter API:単純な状況を更新(Python)
-
11-10-2019 - |
質問
ってみなければならないというニーズを更新Twitterの状況からPythonのクライアントこのお客様のニーズにアクセスTwitterアカウントできないことかじめ生成されていたoauth_token、秘密に http://dev.twitter.com/pages/oauth_single_token
しかし、サンプルコードにあるようには見えない作りになってみようと考えていま認証"または"誤り"署名..
が色々なpython-twitter図書館がありませんの最新)さんと思われる場合も、誰でもも図書室があり、現在ポスト-ご要望は一部のサンプルコード!
更新: 私たパヴェルのソリューションで作品として新しいメッセージは一つの単語の長いものなどスペースを含む人にとってこのエラー:
status = api.PostUpdate('hello world')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\site-packages\python_twitter\twitter.py", line 2459, in PostUpdate
self._CheckForTwitterError(data)
File "C:\Python26\lib\site-packages\python_twitter\twitter.py", line 3394, in _CheckForTwitterErro
r
raise TwitterError(data['error'])
python_twitter.twitter.TwitterError: Incorrect signature
場合には更新がでの作品:
status = api.PostUpdate('helloworld')
{'status': 'helloworld'}
うかが起こっているか?
もちろん、事前に
Hoff
解決 2
別のライブラリを使用してこの問題を解決することができました。そのため、参照のためにソリューションを投稿してください。
import tweepy
# http://dev.twitter.com/apps/myappid
CONSUMER_KEY = 'my consumer key'
CONSUMER_SECRET = 'my consumer secret'
# http://dev.twitter.com/apps/myappid/my_token
ACCESS_TOKEN_KEY= 'my access token key'
ACCESS_TOKEN_SECRET= 'my access token secret'
def tweet(status):
'''
updates the status of my twitter account
requires tweepy (https://github.com/joshthecoder/tweepy)
'''
if len(status) > 140:
raise Exception('status message is too long!')
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
result = api.update_status(status)
return result
他のヒント
おがこ http://code.google.com/p/python-twitter/
残念ながらのドキュメントが存在しないをするものであるとの最後にリリースしたのは2009年。
に使用しましたコードからhg:
wget http://python-twitter.googlecode.com/hg/get_access_token.py
wget http://python-twitter.googlecode.com/hg/twitter.py
後長くアプリの登録プロセス( http://dev.twitter.com/pages/auth#register すべてのConsumer keyとsecret.その独自のためのアプリです。
次に必要なものを接続するアプリと、お客様はご自身のアカウントの編集get_access_token.py に従ってソース(sic!) るようにしました。すべてのTwitterアクセストークン鍵と秘密裏に行なわれる。
>>> import twitter
>>> api = twitter.Api(consumer_key='consumer_key',
consumer_secret='consumer_secret', access_token_key='access_token',
access_token_secret='access_token_secret')
>>> status = api.PostUpdate('I love python-twitter!')
>>> print status.text
I love python-twitter!
でも私にとって http://twitter.com/#!/pawelprazak/status/16504039403425792 (投稿をしてください視の皆様へ)
るとしても高い評価を得ていなければならないようなコードなので、いろんので、使ってみて下さい。
編集:私の例がより鮮明になります。
最近の立地のためのPython-Twitterの文書は、今ではGitHubは、googleページコードポイントです。)
なお、現在の必要がなくなり利用のコマンドラインツールとpython-twitterへのアクセストークンおよび営業秘密 https://dev.twitter.com ご請求の場登録アプリです。
一度の異なる資格の価値、最初にやりたいことが試験によって作成、APIの試験
api=ます。Api(consumer_key='consumer_key', consumer_secret='consumer_secret', access_token_key='access_token', access_token_secret='access_token_secret')
印刷します。VerifyCredentials()
このままの場合の資格が働います。する次の手順でパスdebugHTTP=TrueのApi()を呼び出するとすべてのHTTP会話する印刷することもでき、フレームの中にコンテンツをエラーメッセージを表示します。
一度、資格作業してみると良いでしょう話PostUpdate()もGetTimeline()
私はこの質問に関連するものをコードしました。
import tweepy
consumer_key = Your_consumer_key
consumer_secret = Your_consumer_secret
access_token = Your_access_token
access_token_secret = Your_access_token_secret_key
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
single_tweet = 'hello world'
api.update_status(single_tweet)
print "successfully Updated"