timeline_for failure

3 views
Skip to first unread message

Mark Granoff

unread,
Sep 1, 2010, 10:26:20 PM9/1/10
to twitter4r-users
I have updated to twitter4r 0.5.0, and updated come code to use the
new oauth interface. I seem to be able to create a client object, but
then my timeline_for call fails as follows:

/var/lib/gems/1.8/gems/twitter4r-0.5.0/lib/twitter/client/base.rb:
92:in `raise_rest_error': Unauthorized (Twitter::RESTError)
from /var/lib/gems/1.8/gems/twitter4r-0.5.0/lib/twitter/client/
base.rb:97:in `handle_rest_response'
from /var/lib/gems/1.8/gems/twitter4r-0.5.0/lib/twitter/client/
base.rb:23:in `rest_oauth_connect'
from /var/lib/gems/1.8/gems/twitter4r-0.5.0/lib/twitter/client/
timeline.rb:78:in `timeline_for'

Here's the a code snippet. Twitter::Client.new(...) succeeds (I
think), then the timeline_for() call fails. The error above might
suggest that the Client.new() call actually failed, but I'm not sure
(to be honest; I don't quite get all the details of oauth...) Anyway:

client = Twitter::Client.new(:oauth_consumer => { :key =>
CONSUMER_KEY, :secret =>
CONSUMER_SECRET },
:oauth_access => { :key =>
ACCESS_TOKEN, :secret =>
ACCESS_SECRET },
:login => @username, :password =>
@password)

timeline =
client.timeline_for(:me)


For what it's worth, I read the most recent previous post. Most
notably, I don't seem to have the t4r-oauth-... script in my gem. (I'm
running Ubuntu 10.04).

Any help with this is much appreciated. I am happy to provide whatever
else you need to figure this out. :-)

Thanks,
-Mark

Soyapi Mumba

unread,
Sep 2, 2010, 4:21:43 AM9/2/10
to twitter4r-users
I'm also having this problem with the Twitter::Client.new(...)
approach on Ubuntu 10.04. I'm wondering if it's a problem with the
Timestamp being used by Ubuntu/Linux as suggested in this thread:

http://groups.google.com/group/twitter-development-talk/t/64e59e18c4948fa

- Soyapi

On Thu, Sep 2, 2010 at 4:26 AM, Mark Granoff <ma...@granoff.net> wrote:

> For what it's worth, I read the most recent previous post. Most
> notably, I don't seem to have the t4r-oauth-... script in my gem. (I'm
> running Ubuntu 10.04).
>
> Any help with this is much appreciated. I am happy to provide whatever
> else you need to figure this out. :-)

--
Soyapi Mumba
http://soyapi.com/owinna

SP

unread,
Sep 2, 2010, 4:41:53 PM9/2/10
to twitter4r-users
Mark,

I can you remove the :password key-value element of the initializater
Hash? Does that make any difference?

Also can you verify that the consumer key/secret token and the access
key/secret token is correct via another means (i.e. using Twurl
indirectly or via cURL)?

Susan

Mark Granoff

unread,
Sep 2, 2010, 8:48:58 PM9/2/10
to twitter4r-users
Hi Susan,

I think this is what you meant (in terms of the change to the code):


client = Twitter::Client.new(:oauth_consumer => { :key =>
CONSUMER_KEY, :secret =>
CONSUMER_SECRET },
:oauth_access => { :key =>
ACCESS_TOKEN, :secret =>
ACCESS_SECRET },
:login => @username)

Same result.

I created the key/secret tokens on the Twitter site, and I am 99.9%
certain they are valid. Plus, I am not sure how to do what you suggest
with cURL. :-)

-Mark

Mark Granoff

unread,
Sep 3, 2010, 9:50:05 AM9/3/10
to twitter4r-users
I made a bit of forward progress.

I setup a config file with my various keys and secrets, like so:

prod:
oauth_consumer:
key: ...
secret: ...
oauth_access:
key: ...
secret: ...

As I said, I created these values via Twitter.com, while I was logged
in as me (@granoff).

I changed my code to be thus:

client = Twitter::Client.from_config('twitter.yml', 'prod');
client.authenticate?(@username, @password);

timeline = client.timeline_for(:me)

This works! I get results back from timeline_for(). And, I was able to
post an update.

BUT, I didn't authenticate in the code above as me; I used a different
username/password pair. And I expected (hoped) that the tweet would
show up as coming from that user. But it showed up as tweeted by me.

I need to be able to authenticate as a specific user (who's
credentials I have; it's all legit) and post a tweet as them.

Do I need separate Consumer and Access key/secret pairs for each user?
I don't really understand how this extra layer works... :-(

Thanks for your help. It's much appreciated.

-Mark

On Sep 2, 4:41 pm, SP <mbbx6...@gmail.com> wrote:

Mark Granoff

unread,
Sep 3, 2010, 3:47:40 PM9/3/10
to twitter4r-users
I answered my last question (about key/secret pairs per user). Of
course, the answer is: Yes! So I figured out how to do that... So now
I have my app's Consumer key/secret, and a unique key/secret per user.

Going back to the Twitter::Client.new() call, I am back to where I
started. That call seems to succeed, but then the timeline_for() call
fails. Using a YAML file for each user (and using
Twitter::Client.from_config()), where only their key/secret is
different (but the app key/secret are always the same) seems less than
ideal, especially if the app's key/secret changes...

Might the problem be that asking for asking calling timeline_for(:me)
is in fact inappropriate in this new authentication model? I'll play
with that, but I am interested in your thoughts on that.

-Mark

Susan Potter

unread,
Sep 3, 2010, 5:09:12 PM9/3/10
to twitter...@googlegroups.com
Mark,

I believe timeline_for(:me) is a special case. If you add the login
at the same level as oauth_consumer Hash then you should be able to
retrieve timeline_for(:me). I should have mentioned this in the
release notes and I apologize for not doing so. No password is
needed, just the login, access key/secret pair for the login and the
application consumer key/secret pair.

HTH,
Susan

> --
> You received this message because you are subscribed to the Google Groups "twitter4r-users" group.
> To post to this group, send email to twitter...@googlegroups.com.
> To unsubscribe from this group, send email to twitter4r-use...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/twitter4r-users?hl=en.
>
>

--
mailto:m...@susanpotter.net
twitter:@SusanPotter
github:mbbx6spp
blog:http://geek.susanpotter.net
linkedin:http://www.linkedin.com/in/susanpotter

Mark Granoff

unread,
Sep 4, 2010, 10:35:29 AM9/4/10
to twitter4r-users
Hi Susan,

First, i can report success using 'key' and 'secret' instead of :key
and :secret.

Thanks for the info about timeline_for(:me). I did some experimenting
and found that with a successfully created client object, without
including :login, that timeline_for(:me) as well as
timeline_for(:user, :id => @username) return correct and identical
results for the user for whom the access_key and access_secret were
provided.

As an aside, when I use a command like timeline_for(:user, :id =>
@username, :count => XX), no matter what value XX is, I get 20 tweets
back. Not so much an issue for me at the moment, but thought I'd
mention it.

I am really pleased that the "symbol vs string" mystery is solved! I
had worked around it by creating per-user YAML files, but I didn't
really like that solution as it duplicated my application token/secret
in too many places. Being able to have per-user configuration files
(which I already had) that each *include* the user's access token/
secret is much more scalable and keeps my code cleaner as well.

-Mark
> > For more options, visit this group athttp://groups.google.com/group/twitter4r-users?hl=en.
Reply all
Reply to author
Forward
0 new messages