Twitter API через OmniAuth на Rails 3, Net :: HTTPUnauthorized hell

Я выполнил руководство по Simple OmniAuth ( http://asciicasts.com/episodes/241-simple-omniauth ), и я могу войти в свою учетную запись Twitter на сервисе. Теперь я хочу получить доступ к API твиттера и твитнуть из приложения. Мой код выглядит следующим образом:

class TwitterController < ApplicationController

def prepare_access_token(oauth_token, oauth_token_secret)
consumer = OAuth::Consumer.new("KEY", "SECRET",
    {
        :site => "http://api.twitter.com"
    })
    # now create the access token object from passed values
    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

def tweet
    # Exchange our oauth_token and oauth_token secret for the AccessToken instance.
    @access_token = prepare_access_token(current_user.token, current_user.secret)

    @response = @access_token.request(:post, "http://api.twitter.com/1/statuses/update.json", :status => "Tweet pela API")

    render :html => @response.body
end

end

Строка рендеринга ничего не делает. Более того, если я добавлю

<%= @response %>

в свое представление, я получу

#

Тем не менее, я могу получить имя пользователя из учетной записи Twitter.

Моя модель пользователя - следующим образом:

class User < ActiveRecord::Base
def self.create_with_omniauth(auth)  
       create! do |user|  
         user.provider = auth["provider"]  
         user.uid = auth["uid"]  
         user.name = auth["user_info"]["name"] 
         user.token = auth['credentials']['token'],
         user.secret = auth['credentials']['secret'] 
       end  
    end  
 end

Что я делаю не так?

5
задан Pedro Vanzella 4 January 2011 в 15:32
поделиться