2009-09-03 10 views
1

私のレールアプリでtwitterに投稿しようとするたびに、最初の投稿 が失敗します。私は簡単な例を示した後、さらに問題を説明します。ここ は、(編集された敏感なもので)コンソールからのライブの例です:Twitterのgemが初めてのステータス更新で失敗する(コンソールの例が含まれています)

>> u = User.find(7) 
=> #<User id: 7, login: "[email protected]", email: 
"[email protected]", crypted_password: "stuff", salt: "stuff", 
twitter_token: "some_twitter_token", twitter_secret: 
"some_twitter_secret", twitter_sn: "some_twitter_sn"> 

>> u.twitter_client 
=> #<Twitter::Base:0x7f11672957a0 @client=#<Twitter::OAuth: 
0x7f1167295728 @csecret="some_c_secret", @ctoken="some_c_token", 
@asecret="some_a_secret", @consumer_options={}, 
@atoken="some_a_token">> 

>> u.twitter_client.update("Hello World") 
=> false 

>> u.twitter_client 
=> #<Twitter::Base:0x7f11672957a0 @client=#<Twitter::OAuth: 
0x7f1167295728 @csecret="some_c_secret", @consumer=#<OAuth::Consumer: 
0x7f1167290bd8 @uri=#<URI::HTTP:0x3f88b3948330 URL:http:// 
twitter.com>, @options={:access_token_path=>"/oauth/ 
access_token", :site=>"http:// 
twitter.com", :oauth_version=>"1.0", :scheme=>:header, :request_token_path=>"/ 
oauth/request_token", :signature_method=>"HMAC- 
SHA1", :http_method=>:post, :authorize_path=>"/oauth/authorize"}, 
@http=#<Net::HTTP twitter.com:80 open=false>, @secret="secret", 
@key="key">, @access_token=#<OAuth::AccessToken:0x7f1167290c78 
@consumer=#<OAuth::Consumer:0x7f1167290bd8 @uri=#<URI::HTTP: 
0x3f88b3948330 URL:http://twitter.com>, @options= 
{:access_token_path=>"/oauth/access_token", :site=>"http:// 
twitter.com", :oauth_version=>"1.0", :scheme=>:header, :request_token_path=>"/ 
oauth/request_token", :signature_method=>"HMAC- 
SHA1", :http_method=>:post, :authorize_path=>"/oauth/authorize"}, 
@http=#<Net::HTTP twitter.com:80 open=false>, @secret="secret", 
@key="key">, @token="token", @response=#<Net::HTTPRequestTimeOut 408 
Request Timeout readbody=true>, @secret="secret">, @ctoken="ctoken", 
@asecret="asecret", @consumer_options={}, @atoken="atoken">> 

>> u.twitter_client.update("Hello World") 
=> <Mash created_at="Thu Sep 03 01:38:21 +0000 2009" favorited=false 
id=3724099662 in_reply_to_screen_name=nil in_reply_to_status_id=nil 
in_reply_to_user_id=nil source="<a href=\"http://www.url.com\" rel= 
\"nofollow\">MyApp</a>" text="Hello World" truncated=false user=<Mash 
created_at="Tue Aug 11 19:47:26 +0000 2009" description=nil 
favourites_count=0 followers_count=4 following=false friends_count=21 
id=64803633 location=nil name="some name" notifications=false 
profile_background_color="9ae4e8" profile_background_image_url="http:// 
s.twimg.com/a/1251923748/images/themes/theme1/bg.gif" 
profile_background_tile=false profile_image_url="http://s.twimg.com/a/ 
1251923748/images/default_profile_normal.png" 
profile_link_color="0000ff" profile_sidebar_border_color="87bc44" 
profile_sidebar_fill_color="e0ff92" profile_text_color="000000" 
protected=false screen_name="screen_name" statuses_count=4 
time_zone=nil url=nil utc_offset=nil verified=false>> 

>> u.twitter_client 
=> #<Twitter::Base:0x7f11672957a0 @client=#<Twitter::OAuth: 
0x7f1167295728 @csecret="csecret", @consumer=#<OAuth::Consumer: 
0x7f1167290bd8 @uri=#<URI::HTTP:0x3f88b3948330 URL:http:// 
twitter.com>, @options={:access_token_path=>"/oauth/ 
access_token", :site=>"http:// 
twitter.com", :oauth_version=>"1.0", :scheme=>:header, :request_token_path=>"/ 
oauth/request_token", :signature_method=>"HMAC- 
SHA1", :http_method=>:post, :authorize_path=>"/oauth/authorize"}, 
@http=#<Net::HTTP twitter.com:80 open=false>, @secret="secret", 
@key="key">, @access_token=#<OAuth::AccessToken:0x7f1167290c78 
@consumer=#<OAuth::Consumer:0x7f1167290bd8 @uri=#<URI::HTTP: 
0x3f88b3948330 URL:http://twitter.com>, @options= 
{:access_token_path=>"/oauth/access_token", :site=>"http:// 
twitter.com", :oauth_version=>"1.0", :scheme=>:header, :request_token_path=>"/ 
oauth/request_token", :signature_method=>"HMAC- 
SHA1", :http_method=>:post, :authorize_path=>"/oauth/authorize"}, 
@http=#<Net::HTTP twitter.com:80 open=false>, @secret="secret", 
@key="key">, @token="token", @response=#<Net::HTTPOK 200 OK 
readbody=true>, @secret="secret">, @ctoken="ctoken", 
@asecret="asecret", @consumer_options={}, @atoken="atoken">> 

最初の時間をu.twitter_client行うこと@consumerが設定されていない適切として、クライアントと最初の時間を設定 ではないことは明らかです 私はu.twitter_client.update( "Hello World")をやっています。クライアント を見ると、408リクエストのタイムアウトの問題が表示されています。これは実際には です。誰も私がこれをどのように修正できるか知っていますか?上記の例が使用されている以下の私の関数は です。

def twitter_oauth 
    @oauth ||= Twitter::OAuth.new(ConsumerConfig['twitter_token'], 
ConsumerConfig['twitter_secret']) 
end 

def twitter_client 
    @client ||= begin 
    twitter_oauth.authorize_from_access(twitter_token, 
twitter_secret) 
    Twitter::Base.new(twitter_oauth) 
    end 
end 

更新 私はまた、この問題は私の本番環境で発生することに注意してください。このプロセスは私の開発環境でうまくいきます。

ありがとうございます!

答えて

0

運用環境の資格情報を変更する必要がありますか? Twitterのサイトでアプリケーションを設定すると、返すURLを指定するだけで、戻り値(セキュリティ機能)としてプログラムで渡すURLはすべてスキップされます。

+0

私はプロダクションのために登録された別々のoauthアプリを持っています、そして、資格証明はこれを反映しています。また、この場合、最初のつぶやきだけが失敗する理由は理解できません。 – Tony

+0

私は、なぜそれが生産対生産で起こっていたのか理解しようとしていました。もう1つの興味深いテストは、一時的にクラスキャッシングをfalseに変更することです(標準的なdev設定をミラーリングします)。 –

+0

よろしくお願いします。試してみましょう – Tony

関連する問題