sferik / twitter-ruby Goto Github PK
View Code? Open in Web Editor NEWA Ruby interface to the Twitter API.
Home Page: http://www.rubydoc.info/gems/twitter
License: MIT License
A Ruby interface to the Twitter API.
Home Page: http://www.rubydoc.info/gems/twitter
License: MIT License
Any chance we could get the calls updated?
title says it all. Mash redefines stringify_keys and stringify_keys! to have deep-stringify type functionality, but it should not be modifying Hash.
Can we avoid using (or patch) mash?
Is there some kind of build in caching? api_cache seems to be quite interesting and easy to use. but it does not work to marshall the array of mashes. as a workarount i can go through to_json, but that seems really odd
tag.locals.tweets = JSON.parse(APICache.get("list_timeline_#{tag.locals.user}_#{tag.attr['list']}_#{tag.locals.max}".dup, :cache => 3600) do
begin
Twitter.list_timeline(tag.locals.user,tag.attr['list'], {:page => 1, :per_page => tag.locals.max} ).to_json
rescue Exception => e
logger.error "Unable to fetch user list: #{e.inspect}"
raise APICache::InvalidResponse
end
end).map{|hash| Hashie::Mash.new(hash)}
this "works" but it does not look right
http://github.com/mloughran/api_cache is what I was looking for to use
or is this whole idea not appealing?
Can you please bump up the OAuth gem to 0.3.5.
Twitter dropped /statuses/replies in favor of /statuses/mentions.
Likewise, this branch deprecates #replies in favor of #mentions.
http://github.com/rmm5t/twitter/commits/replies_to_mentions
For building desktop applications, it'd be really handy to support XAuth. (A nice summary is here: http://www.reynoldsftw.com/2010/03/using-xauth-an-alternate-oauth-from-twitter/)
I might be able to provide a patch to add this support, but need to know how best to generate the OAuth authorisation scheme (nonce, timestamp, etc), which is used by the Twitter API method described here: http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-oauth-access_token-for-xAuth
Does anybody know how best to generate the authorisation scheme? (How) can the Ruby OAuth gem be used for this purpose?
could we have someone enabling https support on the oauth and api call?
list_add_member works just fine but when trying list_remove_user i get
this error
Twitter::RateLimitExceeded: (400): Bad Request - You must specify a
member
Which is the same error you get if you use the api via curl and leave
off the id
http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-DELETE-list-members
It has nothing to do with the rate limit. twitter gem just returns all
400's as a ratelimitexceded. There is no rate limit for adding and
removing list items and also my account is white listed.
I think this may be a new change to twitter, but user-agents are now required or else it will return a 400 Bad Request.
Add this line to work around it for now:
Twitter::Search.default_options = {:headers => {'User-Agent' =>
'YOUR_USER_AGENT_STRING'}}
Crack seems to have problem's with Twitter's JSON format. If I use the Rails json gem instead, I have no problems.
/Library/Ruby/Gems/1.8/gems/crack-0.1.1/lib/crack/json.rb:14:in `parse': Invalid JSON string (Crack::ParseError)
Twitter gem uses OAuth 0.3.2 instead of the current version.
Hey,
I was looking into this in the twitter gem and it appears there is no way to know if a message post was successful or not. Is this the case with the twitter API?
I know I know, should limit the text to 140 first. I think the lib should still throw an exception in this case... (not if the text is too long) but if the message post failed.
What you think?
Best,
Dave
twitter 0.9.5
twitter.rb:67
now
def self.make_friendly(response)
data = parse(response)
was
def self.make_friendly(response)
raise_errors(response)
data = parse(response)
when u try to post a msg "DM of company fired his employees" DM as deputy manager it should fail.
Is there any provision to escape it? Ideally it should be functionality in the client.
I tried to upgrade to 0.9.2 and started getting this error all over. I pulled down the code and I see that the tests for 0.9.2 don't pass due to the same error. I'll push a patch for this to my fork shortly.
twitter.com --> api.twitter.com/1
When you request a search with a :since_id parameter too old, according to Twitter:
This method will return an HTTP 404 error if since_id is used and is too old to be in the search index
which results in a +Crack::ParseError+ exception
Twitter gem should use pessimistic version constraints for dependencies. My proposal:
oauth ~> 0.3.5
mash ~> 0.0.3
httparty ~> 0.4.3
Right now the dependencies are:
oauth (>= 0.3.5, runtime)
mash (= 0.0.3, runtime)
httparty (= 0.4.3, runtime)
This means when newer "mash" is released (github version is v0.0.7 now) with much needed bugfixes, twitter gem will currently not load it because it's locked to v0.0.3. With a pessimistic version constraint, it will load any newer 0.0.x version.
Also, currently if an incompatible new OAuth gem is released—let's imagine v0.5.0—twitter gem will load it without second thought and that might break functionality. With a pessimistic version constraint, it will only load newer 0.3.x releases, but never 0.4.0 or higher.
I'm getting an 401 Unauthorized Incorrect Signature. I'm using twitter 0.7.9 and oauth 0.3.6.
Sometimes this error occured and sometimes i got no error, i've tried to find out what's the problem but i got no clue. Looks like the error occured on verify credentials, here is the stack trace of the error:
Twitter::Unauthorized: (401): Unauthorized - Incorrect signature
from /usr/local/lib/ruby/gems/1.8/gems/twitter-0.7.9/lib/twitter/request.rb:75:in raise_errors' from /usr/local/lib/ruby/gems/1.8/gems/twitter-0.7.9/lib/twitter/request.rb:63:in
make_friendly'
from /usr/local/lib/ruby/gems/1.8/gems/twitter-0.7.9/lib/twitter/request.rb:42:in perform' from /usr/local/lib/ruby/gems/1.8/gems/twitter-0.7.9/lib/twitter/request.rb:6:in
get'
from /usr/local/lib/ruby/gems/1.8/gems/twitter-0.7.9/lib/twitter/base.rb:315:in perform_get' from /usr/local/lib/ruby/gems/1.8/gems/twitter-0.7.9/lib/twitter/base.rb:145:in
verify_credentials'
from /home/dimas/Works/my_app/app/models/twitter_account.rb:42:in `backup'
from (irb):5
Thanks,
Dimas Priyanto
Hi, when installing twitter gem version 0.9.5, I keep getting the following error when requiring the gem -- looks like it is calling the yajl dependency incorrectly maybe:
require 'twitter'
LoadError: Failed to load /usr/local/lib/ruby/gems/1.8/gems/yajl-ruby-0.7.5/lib/yajl_ext.bundle
from /usr/local/lib/ruby/gems/1.8/gems/yajl-ruby-0.7.5/lib/yajl_ext.bundle
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in
require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:innew_constants_in' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in
require'
from /usr/local/lib/ruby/gems/1.8/gems/yajl-ruby-0.7.5/lib/yajl.rb:2
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:inrequire' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in
new_constants_in'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:inrequire' from /usr/local/lib/ruby/gems/1.8/gems/twitter-0.9.5/lib/twitter.rb:5 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in
require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:innew_constants_in' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in
require'
from (irb):2>> exit
Installing Twitter gem version 0.9.4 instead of 0.9.5 fixes the problem for me. Thought you should be aware
list_subscribers uses a cursor. Currently there's no way to pass this in.
It's probably a simple mod in base.rb to pass through the query param as is done with list_members.
Twitter has updated the friendship_create method so that it can consume an explicit user_id or screen_name parameter vs the potentially ambiguous "id", which could be either of those values.
Would be best to reflect this specificity in the Twitter gem. (Sorry, I'm a n00b. Wouldn't knwow where to begin.)
Note, I haven't taken a pass over the Twitter API to see if this change was made to other methods that consume "id" as a param.
Thanks.
I just started using this gem and noticed that when you inspect a single status (class Hashie::Mash) the method .url always returns nil. This was an issue for me, so I've found a solution with a function that seems to return the url address of a single status:
"http://twitter.com/#{from_user}/status/#{id}"
I hope this is of help.
Twitter::Base.lists method doesn't support "cursor" option.
API does: http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-GET-lists
Would be great to have this option there.
Thanks.
In an attempt to use the Twitter gem in my Rails app, I'm being presented with the following exception: uninitialized constant Twitter::OAuth
It occurs when trying to instantiate OAuth.
oauth = Twitter::OAuth.new(ServiceAPIKeys.twitter['api_key'], ServiceAPIKeys.twitter['secret_key'])
I have all of the dependencies installed and the gems are unpacked in my vendor/gem directory.
Thoughts?
Can't find how to call this API: http://apiwiki.twitter.com/Twitter+REST+API+Method%3A-blocks-blocking
Please point out if I missed it.
The methods on the Twitter class (firehose, friend_ids, follower_ids, status, user) assume that no errors will occur, but all of them can at least return a 50x error. An example using FakeWeb:
>> FakeWeb.register_uri(:get, 'http://twitter.com/statuses/public_timeline.json', ?> :string => '{"request":"\/statuses\/public_timeline.json","error":"Bad gateway"}', ?> :status => ['502', 'Bad Gateway']) => [#["502", "Bad Gateway"], :string=>"{\"request\":\"\\/statuses\\/public_timeline.json\",\"error\":\"Bad gateway\"}"}, @method=:get, @uri="http://twitter.com/statuses/public_timeline.json", @times=1>] >> Twitter.firehose NoMethodError: undefined method `stringify_keys' for ["request", "/statuses/public_timeline.json"]:Array from /usr/lib/ruby/gems/1.8/gems/mash-0.0.3/lib/mash.rb:131:in `deep_update' from /usr/lib/ruby/gems/1.8/gems/mash-0.0.3/lib/mash.rb:50:in `initialize' from /usr/lib/ruby/gems/1.8/gems/twitter-0.6.11/lib/twitter.rb:34:in `new' from /usr/lib/ruby/gems/1.8/gems/twitter-0.6.11/lib/twitter.rb:34:in `firehose'
happens periodically, presumably when twitter search services returns a string for a response instead of a hash?
After upgrading to 0.9.8, when redirecting to request_token.authorize_url it is missing http:// before the URL. It works in 0.8.4.
As the number of calls we make to twitter increases, we would like it to be async. Any chance of adding support for async (thru em-http perhaps)?
Thx!
"Sign in with Twitter" is the pattern of authentication
that allows users to connect their Twitter account
with third-party services in as little is one click.
From Twitter API Wiki:
This home_timeline is identical to statuses/friends_timeline except it also contains retweets, which statuses/friends_timeline does not (for backwards compatibility reasons). In a future version of the API, statuses/friends_timeline will go away and be replaced by home_timeline.
This branch adds support for home timeline:
http://github.com/coderifous/twitter/commits/add_home_timeline
Not sure if this is an issue with Crack or with this lib, but every time I try to create a friendship, I get this error:
base.friendship_create('anyone')
Crack::ParseError: Invalid JSON string
from /Library/Ruby/Gems/1.8/gems/crack-0.1.2/lib/crack/json.rb:14:inparse' from /Library/Ruby/Gems/1.8/gems/twitter-0.6.8/lib/twitter/request.rb:73:in
parse'
from /Library/Ruby/Gems/1.8/gems/twitter-0.6.8/lib/twitter/request.rb:48:inmake_friendly' from /Library/Ruby/Gems/1.8/gems/twitter-0.6.8/lib/twitter/request.rb:34:in
perform'
from /Library/Ruby/Gems/1.8/gems/twitter-0.6.8/lib/twitter/request.rb:10:inpost' from /Library/Ruby/Gems/1.8/gems/twitter-0.6.8/lib/twitter/base.rb:162:in
perform_post'
from /Library/Ruby/Gems/1.8/gems/twitter-0.6.8/lib/twitter/base.rb:76:in `friendship_create'
We are having the handle errors such as the ones below:
rescue Errno::ETIMEDOUT,
Errno::ECONNREFUSED,
Timeout::Error,
StandardError => e
Shouldnt they be caught at the API level and appropriate exception be bubbled up to us?
The error happens when I try to invoke
client.friendship_exists?("railshoster", "railsvorlesung")
Here the full stack trace:
I am not sure if I am calling the method correctly but I am not able to get any results back when I specify the since_date:
Example:
Twitter::Search.new.from('user').since_date('2010-07-07').fetch().results, returns nil
Currently there’s no way to use twitter gem along with ExtLib gem (which is e.g. used by DataMapper).
Both ExtLib and mash gem (used by twitter) declare separate notions of a Mash class with different semantics. This results in infinite recursion (“stack level too deep” error).
This bug is also posted here: https://mbleigh.lighthouseapp.com/projects/10112-mash/tickets/3-mash-conflicting-with-extlib
I'd love to be able to setup a proxy so I can use my whitelisted IP. I'm hosted on a cloud instance, so this is a requirement for me. I'm not entirely sure how I could set the proxy other than editing the gem.
I'm trying to retrieve a pared down user timeline but the skip_user option (detailed here: http://dev.twitter.com/doc/get/statuses/user_timeline) doesn't seem to be having any effect. I'm still getting full users back on my statuses. Not sure if this is a problem with the gem or with twitter. Cheers.
It is sometimes useful to see if the client is authorized or not, and here is the method I added to the Twitter::Base class to check using an example taken from twitter_oauth:
def authorized?
oauth_response = client.access_token.get('/account/verify_credentials.json')
oauth_response.class == Net::HTTPOK
end
I am sure there is a better way of doing this, but this is the way that I am doing it and it isn't taking an extra API Hits.
Thanks,
Dan
Are you going to support twitter streaming api in this gem?
On Ruby 1.9.1 (not tested 1.8.7):
The array I'm passing as arguments: ["itv1", "cloggingchris", "ToryatSea", "Conservatives", "TheOrwellPrize", "timespolitics"] The array the splat returns within the function: [["itv1", "cloggingchris", "ToryatSea", "Conservatives", "TheOrwellPrize", "timespolitics"]] /usr/local/lib/ruby/gems/1.9.1/gems/twitter-0.9.4/lib/twitter.rb:89:in `raise_errors': (404): Not Found (Twitter::NotFound) from /usr/local/lib/ruby/gems/1.9.1/gems/twitter-0.9.4/lib/twitter.rb:67:in `make_friendly' from /usr/local/lib/ruby/gems/1.9.1/gems/twitter-0.9.4/lib/twitter/request.rb:42:in `perform' from /usr/local/lib/ruby/gems/1.9.1/gems/twitter-0.9.4/lib/twitter/request.rb:6:in `get' from /usr/local/lib/ruby/gems/1.9.1/gems/twitter-0.9.4/lib/twitter/base.rb:356:in `perform_get' from /usr/local/lib/ruby/gems/1.9.1/gems/twitter-0.9.4/lib/twitter/base.rb:111:in `users' from /home/james/backchat/lib/backchat/parser.rb:103:in `lookup_mentioned_users' from bin/parser_test:11:in `'
As a hotfix, simply selecting [0] of the splat return works, but this probably breaks 1.8.7 if this works there, so a more robust fix is required.
Hi
Im not sure if this is a problem with the twitter gem or oauth gem, although twitter gem 0.9.5 has worked fine with the oauth gem 0.3.6 i have been using previously.
When making any api calls i get the following error:
client.rate_limit_status
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.downcase
from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/request_proxy/base.rb:92:innormalized_uri' from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/request_proxy/base.rb:112:in
signature_base_string'
from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/signature/base.rb:66:insignature_base_string' from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/signature/hmac/base.rb:9:in
digest'
from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/signature/base.rb:54:insignature' from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/signature.rb:20:in
sign'
from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/client/helper.rb:44:insignature' from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/client/helper.rb:67:in
header'
from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/client/net_http.rb:80:inset_oauth_header' from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/client/net_http.rb:35:in
send'
from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/client/net_http.rb:35:inoauth!' from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/consumer.rb:208:in
sign!'
from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/consumer.rb:177:increate_signed_request' from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/consumer.rb:149:in
request'
from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/tokens/consumer_token.rb:25:inrequest' from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/tokens/access_token.rb:11:in
request'
from /Users/eddy/.gem/ruby/1.8/gems/oauth-0.3.6/lib/oauth/tokens/access_token.rb:24:inget' from /Users/eddy/.gem/ruby/1.8/gems/twitter-0.9.7/lib/twitter/request.rb:48:in
perform_get'
from /Users/eddy/.gem/ruby/1.8/gems/twitter-0.9.7/lib/twitter/request.rb:42:insend' from /Users/eddy/.gem/ruby/1.8/gems/twitter-0.9.7/lib/twitter/request.rb:42:in
perform'
from /Users/eddy/.gem/ruby/1.8/gems/twitter-0.9.7/lib/twitter/request.rb:6:inget' from /Users/eddy/.gem/ruby/1.8/gems/twitter-0.9.7/lib/twitter/base.rb:374:in
perform_get'
from /Users/eddy/.gem/ruby/1.8/gems/twitter-0.9.7/lib/twitter/base.rb:192:in `rate_limit_status'
Any ideas?
Thanks
It appears that the focus is totally on twitter and support for other end points is being yanked out.
As of 0.9.5 base API version is being hard coded to 1 and they are is no way to change.
Removal of basic authentication 0.9.7 (http://twitter.com/pengwynn/status/14735702512)
Pls note that there are folks like us that use it with other end points. Can we assume that you will continue to support other end points? We really hope you do, happy to provide a patch for the API versioning later this evening.
Thx! Pls revert!
what about adding count option to user_timelime
e.g. Twitter::Search.new.phrase("New York Mets").fetch
Slightly confused here.
Two code snippets:
oauth = Twitter::OAuth.new(consumer_key, consumer_secret)
@auth_url = oauth.request_token.authorize_url
Following the URL gives me the "Deny/Allow screen with the correct consumer name - so twitter has found the correct consumer info.
oauth.authorize_from_request(consumer_key, consumer_secret, pin)
access_token = oauth.access_token
On the authorize_from_request I get a 401. Debugging the call shows that the response from twitter is:
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<request>/oauth/access_token</request>
<error>Invalid / expired Token</error>
</hash>
I have this consumer pair working fine using twitter4j in java - so the consumer seems OK on the twitter side.
Any ideas why this is failing? Have I missed something obvious in the code here?
I guess this is really a yajl-ruby issue but I thought other 0.9.5 twitter users might verify this.
We get seg faults on cucumber features with json requests when we use twitter 0.9.5 and it seems to be an issue with yajl-ruby:
.../Users/jonathangreenberg/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-2.3.5/lib/active_support/json/encoding.rb:70: [BUG] Bus Error
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.8.0]
Note that this was very tricky to track down because even reverting to older twitter gems (e.g. 0.8.3) would still have the seg fault until the yajl-ruby gem was removed even though there does not appear to be a dependency on yajl-ruby.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.