2012-04-24 12 views
0

私はtwnitter経由でユーザーを認証するためにomniauthを使用しています。 omn​​iauthはアクセストークンを提供します。今、私はtwitterにgetまたはpost要求を送信したい。私は宝石を使いたくない。私はnet :: httpとしたい。アクセストークンを使用してルビーのルビーでTwitterでGETしPOSTする方法

twitterのAPIドキュメントでも!私はこのための良いチュートリアルを見つけることができません

いずれかを助けることができますか?おかげ

答えて

2

Hereは、それは今あなたがそれを使用しようとしている、あなたはトークンとomniauthから秘密を持っているので、あなたが必要な正確に何であるので:

def prepare_access_token(oauth_token, oauth_token_secret) 
    consumer = OAuth::Consumer.new("APIKey", "APISecret", { :site => "https://api.twitter.com", :request_token_path => '/oauth/request_token', :access_token_path => '/oauth/access_token', :authorize_path => '/oauth/authorize', :scheme => :header }) 
    token_hash = { :oauth_token => oauth_token, :oauth_token_secret => oauth_token_secret } access_token = OAuth::AccessToken.from_hash(consumer, token_hash) 
    return access_token 
end 

次に、あなたは、例えば、ポストつぶやき:

msg = {'status' => 'Hey look I can tweet via OAuth!'} 
access_token = prepare_access_token(token, secret) 
response = access_token.post('https://api.twitter.com/1/statuses/update.json', msg, { 'Accept' => 'application/xml' }) 

詳細については、リンク先の記事をお読みください。

+0

これは私のために働いてくれてありがとう – santosh

関連する問題