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ならこれで変更できる

【OAuth認証版】モザイクアートのためのリフォロープログラム Twitter-Following



※Twitterはスパム対策でフォローリムーブを多数繰り返すアカウントにフォロー制限をかけることがあります。ご利用は計画的に!


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

articon = 'miuchan' #使うアイコンのusername この場合 http://twitter.com/miuchan1
oauth = Twitter::OAuth.new('consumer token', 'consumer secret')
oauth.authorize_from_access('access token', 'access secret')
client = Twitter::Base.new(oauth)

#Remove Section
i = 1
while i < 37
followlist = articon + i .to_s
begin
 client.friendship_destroy followlist
rescue
puts 'unfollowでなんかのエラー'
puts 'リトライ'
sleep 5
retry
end
i = i + 1
end

#Follow Section
i = 1
while i < 37
followlist = articon + i .to_s
begin
client.friendship_create followlist
rescue
puts 'followでなんかのエラー'
puts 'リトライ'
sleep 5
retry
end
i = i + 1
end


下準備

まずRubyをパソコンで使えるようにして、例えばWindowsならRubyGems Package Managerを起動してgem install twitter
次に、頑張ってアカウントを36個取る。
ちなみにGmailなら
hoge@gmail.com
hoge+icon1@gmail.com
hoge+icon2@gmail.com
    …
のように+の後に付け足せばいくらでもメールアドレスを増殖できます。
アイコン画像は分割結合「あ」などのフリーソフトでサクッと36分割

OAuth認証

2010年6月 8月からBasic認証が廃止されてusernameとpasswordだけではAPI動かせなくなるらしいのでOAuth認証でアレします。RubyのTwitterClientで任意のアプリケーション名を表示する方法: http://www.ffront.jp/diary/118 なんかとてもわかりやすくていいと思います。


使い方

赤字の部分を書き換える
上のプログラムの場合モザイクアート用捨てアカのusernameが
icon1
icon2
icon3
 ・
 ・
 ・
icon36
となってる場合に使えます。
ランダムに登録済みの場合下の赤い部分にアート用usernameを36列入力


使う方のプログラムをメモ帳にコピペしてnantoka.rbの名前で保存
コマンドプロントで
cd c:\ruby
ruby nantoka.rb

最初に36個フォローするときは #Remove Section の部分削るなどする
なんかあったら@dotlinerまで。Good Luck.
 
臼経ビジネスオンライン | TNB