Subscribe News Feed Subscribe Comments

Twitterのアイコンを変更するスクリプト


Ruby Twitter Gem を使って Twitterのアイコンを変える


#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'

username = 'username' 
password = 'password' 
twitter = Twitter::Base.new(Twitter::HTTPAuth.new(username, password))

pic = open("./iconname.jpg", "r")
twitter.update_profile_image(pic)

とりあえずこれでアイコン画像をアップロードできるので


i = 1
ii =35
while i < 37
usernames = (username + i.to_s)
twitter = Twitter::Base.new(Twitter::HTTPAuth.new(usernames, password))
picname = ("./iconname"+ii.to_s+".png")
pic = open(picname, "r")
begin
twitter.update_profile_image(pic)
puts (i.to_s + '個変更した')
rescue
sleep 1
puts 'retry'
retry
end
i = i + 1
ii = ii -1
end
36アカウントのフォロー絵はこんな感じで画像変えてる ただし6月からBasic認証が廃止されるので工夫が必要

oauth = Twitter::OAuth.new('consumer token', 'consumer secret')
oauth.authorize_from_access('access token', 'access secret')
client = Twitter::Base.new(oauth)
pic = open("./iconname.jpg", "r")
client.update_profile_image(pic)
OAuthならこれで変更できる

1 コメント:

匿名 さんのコメント...

Twitterからきますた。
あのアイコンのキャラなんですか?

コメントを投稿

 
臼経ビジネスオンライン | TNB