TwitterAPIã®BASICèªè¨¼ã¯è¿ã
å»æ¢ãããä»å¾ã¯OAuth/xAuthã«ã·ããããã¾ãã
æ··ä¹±ãã¦ããéçºè
ãå¤ãã¨æãã®ã§ãä»åã¯OAuth対å¿ãªTwitterBotãä½ããã¨ãåæã«ãã¦ããã®ç°¡åãªããæ¹ãåç»ã«æ®ã£ã¦ã¿ã¾ãããã¹ã¯ãªã¼ã³ãã£ã¹ãã¨ãããã¤ã§ãã
åç»ã®å 容
è£è¶³ï¼AccessTokençºè¡ã«ä½¿ç¨ããã¹ã¯ãªãã
åç»ã®ä¸ã§ãAccessTokenã®çºè¡ã«ã俺ãæ¸ããã¹ã¯ãªããã使ã£ã¦ãã¾ãã
ããã§ãã
http://gist.github.com/388067
require 'twitter_oauth' print 'Consumer Key> ' consumer_key = gets.chomp print 'Consumer Secret> ' consumer_secret = gets.chomp t = TwitterOAuth::Client.new( :consumer_key => consumer_key, :consumer_secret => consumer_secret ) req = t.request_token puts 'OK' puts "please access and get PIN: #{req.authorize_url}" print 'PIN> ' pin = gets.to_i acc = t.authorize( req.token, req.secret, :oauth_verifier => pin ) puts "Authorized: #{t.authorized?}" puts "Access Token: #{acc.token}" puts "Access Secret: #{acc.secret}"
è£è¶³ï¼ã»ãã¥ãªãã£ã«ã¤ãã¦
åç»ä¸ã§ã¯Consumer Keyã¨ãAccess Tokenã®ã»ãã¥ãªãã£çãªæå³åãã«ã¤ãã¦èª¬æãã¦ãã¾ããã
åç»ä¸ã§ã¯ãã¹ãç¨ã«ç»é²ããã¢ããªã±ã¼ã·ã§ã³ãªã®ã§ãæ¼ãã¦ãã¾ã£ã¦ãåé¡ããã¾ããã§ããï¼åç»ã§ä½æããã¢ããªã±ã¼ã·ã§ã³ã¯ããåé¤ãã¦ãã¾ããï¼ããããããã¯ç¹å¥ãªå ´åã ã£ãããã§ãã
詳ãã説æã¯ä»ã®æç®ã«ä»»ãã¾ããããããã¯æ¬æ¥å
¬éãã¦ã¯ããã¾ããã
å¤ãè¨ãæ¹ã«ç½®ãæããã¨ãConsumer Key/Secretã¯ãã¢ããªã±ã¼ã·ã§ã³ã®ãã¹ã¯ã¼ãããAccess Token/Secretã¯ãï¼ã¢ããªã«å¯¾ããï¼Twitterã¢ã«ã¦ã³ãã®ãã¹ã¯ã¼ããã¨åãæå³ãæã¡ã¾ããã½ã¼ã¹ã³ã¼ãã¨ä¸ç·ã«å
¬éããªãããã«æ³¨æãã¦ãã ããã
ããããæ¼ãã¦ãã¾ãã¨ãã¢ã«ã¦ã³ãã®ãªããã¾ããå¯è½ã§ããï¼ãã ãããããã ãã§ã¯ã¢ã«ã¦ã³ãèªä½ã®ä¹ã£åãã¯é£ããã§ãããï¼ã
è£è¶³ï¼ã©ã¤ãã©ãªã«ã¤ãã¦
ä»åã¯ãtwitter_oauth ã¨ããgemã©ã¤ãã©ãªã使ã£ã¦ãã¾ãã
ãã®ã©ã¤ãã©ãªã¯ãAPIã®ç¶²ç¾
æ§ãé«ããé »ç¹ã«ã¡ã³ããã³ã¹ããã¦ãããä»å¾ã«æå¾
ãã§ãã¾ãã
ãã¾Rubyã§Twitter APIãããããªããå人çã«ã¯ãã£ã¨ããªã¹ã¹ã¡ã®ã©ã¤ãã©ãªã§ãã
ã¤ãæè¿ãRuby1.9ã§ãåãããã«ãªãã¾ããï¼oauth-0.4.0以éï¼ã