从e/TextMate发布到Twitter
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从e/TextMate发布到Twitter相关的知识,希望对你有一定的参考价值。
Adapted from http://journal.mychores.co.uk/articles/2007/01/21/updating-twitter-from-ruby-rails
#!/usr/bin/env ruby require 'net/http' require 'uri' require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb" TW_USER = 'yourusername' TW_PASS = 'yourpassword' TW_URL = 'http://twitter.com/statuses/update.xml' MAX_LEN = 140 message = STDIN.read.chomp if message.length > MAX_LEN puts "Sorry, your message was #{message.length} characters long; the limit is #{MAX_LEN}." TextMate.exit_show_tool_tip elsif message.empty? puts "No message text selected!" TextMate.exit_show_tool_tip end begin url = URI.parse(TW_URL) req = Net::HTTP::Post.new(url.path) req.basic_auth TW_USER, TW_PASS req.set_form_data({'status' => message}) begin res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } case res when Net::HTTPSuccess, Net::HTTPRedirection if res.body.empty? puts "Twitter is not responding properly" TextMate.exit_show_tool_tip else puts 'Twitter update succeeded' TextMate.exit_show_tool_tip end else puts 'Twitter update failed for an unknown reason' # res.error! TextMate.exit_show_tool_tip end rescue puts $! #puts "Twitter update failed - check username/password" TextMate.exit_show_tool_tip end rescue SocketError puts "Twitter is currently unavailable" TextMate.exit_show_tool_tip end
以上是关于从e/TextMate发布到Twitter的主要内容,如果未能解决你的问题,请参考以下文章
使用 Fabric SDK 从 Twitter 授权中取消时出现授权错误