LoginSignup
6
6

More than 5 years have passed since last update.

Google App Engine for PythonでTweet(API1.1)

Last updated at Posted at 2014-01-07

・Python2.7
・TwitterAPI1.1
・OAuthライブラリ(https://github.com/mikeknapp/AppEngine-OAuth-Library)

tweet.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from google.appengine.ext import webapp

#さきほど取得した各情報をここで指定する
TWITTER_CONSUMER_KEY = 'コンシューマーキー'
TWITTER_CONSUMER_SECRET = 'コンシューマーシークレット'
TWITTER_ACCESS_TOKEN = 'アクセストークン'
TWITTER_ACCESS_TOKEN_SECRET = 'アクセストークンシークレット'

class TweetHandler(webapp.RequestHandler):
  def get(self):
    from extends.GAE_Oauth import oauth
    client = oauth.TwitterClient(TWITTER_CONSUMER_KEY,
                                 TWITTER_CONSUMER_SECRET, None)
    tweet = u"おはよう"
    param = {'status': tweet}
    client.make_request('https://api.twitter.com/1.1/statuses/update.json',
                        token=TWITTER_ACCESS_TOKEN,
                        secret=TWITTER_ACCESS_TOKEN_SECRET,
                        additional_params=param,
                        protected=True,
                        method='POST')
    self.response.out.write(tweet)
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6