http://offsidenow.phpapps.jp/archives/1664
・ Python2.7 ・ TwitterAPI1.1 ・ OAuth library (https://github.com/mikeknapp/AppEngine-OAuth-Library)
tweet.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from google.appengine.ext import webapp
#Specify each information obtained earlier here
TWITTER_CONSUMER_KEY = 'Consumer key'
TWITTER_CONSUMER_SECRET = 'Consumer secret'
TWITTER_ACCESS_TOKEN = 'Access token'
TWITTER_ACCESS_TOKEN_SECRET = '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"Good morning"
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)
Recommended Posts