示例代码:
import tweepy
import os
consumer_key = os.environ['CONSUMER_KEY']
consumer_secret = os.environ['CONSUMER_SECRET']
access_token = os.environ['ACCESS_TOKEN']
access_token_secret = os.environ['ACCESS_TOKEN_SECRET']
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
def lambda_handler(event, context):
method = event['httpMethod']
path = event['path']
if method == 'POST' and path == '/timeline':
timeline = api.home_timeline()
return {
'statusCode': 200,
'body': timeline
}
elif method == 'POST' and path == '/user_timeline':
user_timeline = api.user_timeline()
return {
'statusCode': 200,
'body': user_timeline
}
else:
return {
'statusCode': 404,
'body': 'Not Found'
}