Last active
April 12, 2019 02:27
-
-
Save rickbox/8b528a6b992a94c3288300dab71884ec to your computer and use it in GitHub Desktop.
TwitterAPI_sample1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TopController < ApplicationController | |
def index | |
@user = User.all | |
end | |
def show | |
end | |
def download | |
end | |
def create | |
omniauth = request.env['omniauth.auth'] | |
@client = Twitter::REST::Client.new do |config| | |
config.consumer_key = ENV['CONSUMER_KEY'] | |
config.consumer_secret = ENV['CONSUMER_SECRET'] | |
config.access_token = omniauth.credentials.token | |
config.access_token_secret = omniauth.credentials.secret | |
end | |
user_name = request.env['omniauth.auth']['info']['nickname'] | |
if User.find_by(name: user_name) == nil | |
@user = User.new(name: user_name) | |
@n = 1 | |
m3u8_num = 0 | |
m3u8_arr = [] | |
tweets = [] | |
@client.user_timeline(count: 200).each do |t| | |
if @n == 1 | |
@user.since_id = t.id | |
end | |
@n = @n + 1 | |
@last_id = t.id | |
end | |
for i in 1..2 | |
@client.user_timeline(count: 200,max_id: @last_id - 1).each do |t| | |
@n = @n + 1 | |
@last_id = t.id | |
p t.text | |
end | |
end | |
@user.save | |
else | |
@n = 1 | |
m3u8_num = 0 | |
m3u8_arr = [] | |
tweets = [] | |
@user = User.find_by(name: user_name) | |
@old_since_id = @user.since_id | |
@client.user_timeline(count: 200,since_id: @old_since_id).each do |t| | |
if @n == 1 | |
@user.since_id = t.id | |
@n = @n + 1 | |
end | |
@last_id = t.id | |
p t.text | |
end | |
if @old_since_id != @user.since_id | |
for i in 1..15 | |
@client.user_timeline(count: 200,since_id: @old_since_id, max_id: @last_id - 1).each do |t| | |
@n = @n + 1 | |
@last_id = t.id | |
p t.text | |
end | |
end | |
end | |
@user.save | |
end | |
render :show | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment