Created
March 8, 2012 01:45
-
-
Save clvrobj/1997935 to your computer and use it in GitHub Desktop.
post miniblog, douban oauth with ruby sinatra
This file contains hidden or 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
require 'sinatra' | |
require 'oauth' | |
API_KEY = '' | |
API_SECRET = '' | |
token = '' | |
secret = '' | |
post '/miniblog' do | |
content = params[:content] | |
entry = %Q{ <?xml version='1.0' encoding='UTF-8'?> | |
<entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/"> | |
<content>#{content}</content> | |
</entry> | |
} | |
access_token = OAuth::AccessToken.new( | |
OAuth::Consumer.new( | |
API_KEY, | |
API_SECRET, | |
{ | |
:site=>"http://api.douban.com", | |
:scheme=>:header, | |
:signature_method=>"HMAC-SHA1", | |
:realm=>"http://www.doubandev.com" | |
} | |
), | |
token, | |
secret | |
) | |
access_token.post("/miniblog/saying", entry, {"Content-Type"=> "application/atom+xml"}) | |
end |
This file contains hidden or 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
require 'sinatra' | |
require 'oauth' | |
API_KEY = '' | |
API_SECRET = '' | |
token = '' | |
secret = '' | |
post '/miniblog' do | |
content = params[:content] | |
entry = %Q{ <?xml version='1.0' encoding='UTF-8'?> | |
<entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/"> | |
<content>#{content}</content> | |
</entry> | |
} | |
access_token = OAuth::AccessToken.new( | |
OAuth::Consumer.new( | |
API_KEY, | |
API_SECRET, | |
{ | |
:site=>"http://api.douban.com", | |
:scheme=>:header, | |
:signature_method=>"HMAC-SHA1", | |
:realm=>"http://www.doubandev.com" | |
} | |
), | |
token, | |
secret | |
) | |
access_token.post("/miniblog/saying", entry, {"Content-Type"=> "application/atom+xml"}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment