Re: 401 error using phirehose and OAuth

791 views
Skip to first unread message

Adam Green

unread,
Apr 19, 2013, 7:21:30 AM4/19/13
to 140dev-twitt...@googlegroups.com
There are many possibilities. Twitter error codes get reused for many purposes. Here are some first steps:

1. Are you absolutely sure that no other get_tweets.php script is running for this account on any server? Even a copy that is still using the old basic auth code. Please run 'ps aux' on your servers to make sure. 

2. Make sure you have copied all 4 of the OAuth tokens correctly. 

3. Make sure that your server clock is within 5 minutes of the Twitter server. You can use the api console with any API call to see the Twitter server time. http://140dev.com/twitter-api-console/

If none of these reveal the problem, send me a complete copy of your get_tweets.php script. 

On Fri, Apr 19, 2013 at 5:22 AM, Sam Rowley <wigan...@gmail.com> wrote:

I had the streaming API working perfectly with the old version, using the Twitter account username and password but with the impending Twitter switch over thought it best to switch over to using v1.1 and OAuth. 


I downloaded the newest version of the 140dev frameworks and started from scratch. I have created my application with Twitter and have all the keys in the framework. The paths point to the same place as before when I had it working. And now when I try to run the background processes, not using nohup.


I get the following error when it fires:


Phirehose: Connecting to twitter stream: https://stream.twitter.com/1.1/statuses/filter.json with params: array (  'delimited' => 'length',  'track' => 'divisi',)

Phirehose: Resolved host stream.twitter.com to 199.16.156.20, 199.16.156.110

Phirehose: Connecting to ssl://199.16.156.20, port=443, connectTimeout=5

Phirehose: Connection established to 199.16.156.20

Phirehose: POST /1.1/statuses/filter.json HTTP/1.0

Phirehose: Host: stream.twitter.com:443

Phirehose: Content-type: application/x-www-form-urlencoded

Phirehose: Content-length: 29

Phirehose: Accept: */*

Phirehose: Authorization: OAuth realm="",oauth_consumer_key="RETRACTED",oauth_nonce="RETRACTED",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1366302331",oauth_version="1.0",oauth_token="RETRACTED",oauth_signature="RETRACTED"

Phirehose: User-Agent: Phirehose/0.2.gitmaster +https://github.com/fennb/phirehose

Phirehose: 

Phirehose: delimited=length&track=divisi

Phirehose: 

Phirehose: HTTP failure 1 of 20 connecting to stream: HTTP ERROR 401: Unauthorized (<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Error 401 Unauthorized</title></head><body><h2>HTTP ERROR: 401</h2><p>Problem accessing '/1.1/statuses/filter.json'. Reason:<pre>    Unauthorized</pre>). Sleeping for 10 seconds.


I am guessing this has something to do with the OAuth keys?

--
You received this message because you are subscribed to the Google Groups "140dev Twitter Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 140dev-twitter-fra...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Adam Green
CEO, 140dev.com
CTO, UniteBlue.com
ad...@140dev.com
781-879-2960
@140dev

Paul Valkama

unread,
Apr 19, 2013, 11:21:11 PM4/19/13
to 140dev-twitt...@googlegroups.com, ad...@140dev.com
I had the exact same issue.

I changed the quotes for these:

define(TWITTER_CONSUMER_KEY,'******’);
define(TWITTER_CONSUMER_SECRET,'******’);
define(OAUTH_TOKEN,'******’);
define(OAUTH_SECRET,'******’);

to these:

define('TWITTER_CONSUMER_KEY','******’);
define('TWITTER_CONSUMER_SECRET','******’);
define('OAUTH_TOKEN','******’);
define('OAUTH_SECRET','******’);

Not sure if that is good coding but it worked! Hope that helps ...

Paul

To unsubscribe from this group and stop receiving emails from it, send an email to 140dev-twitter-framework+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

ialexs

unread,
Apr 23, 2013, 12:06:56 AM4/23/13
to 140dev-twitt...@googlegroups.com, ad...@140dev.com
After blaming PHP installation & other things...
point number 3 below solved the  "Unauthorized" problem... 

Somehow the server not syncing to the NTP server and skewed about 10minutes.

Thanks Adam :)

To unsubscribe from this group and stop receiving emails from it, send an email to 140dev-twitter-framework+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Matt Walsh

unread,
Jun 10, 2013, 12:41:22 PM6/10/13
to 140dev-twitt...@googlegroups.com, ad...@140dev.com
Hi--

I'm having the same issue here and I can't figure out what might be wrong.


1. Are you absolutely sure that no other get_tweets.php script is running for this account on any server? Even a copy that is still using the old basic auth code. Please run 'ps aux' on your servers to make sure. 

I downloaded the most recent code from git hub. TwitterStreamJob is the name of my job. 

ps aux | grep "[p]hp batch_index.php TwitterStreamJob" returns nothing.

It's definitely not running. 
 
 2. Make sure you have copied all 4 of the OAuth tokens correctly. 

Array
(
    [oauth_consumer_key] => xxxxxxxxxuq2CgJg
    [oauth_nonce] => xxxxxxxxxa5a05b51af7
    [oauth_signature_method] => HMAC-SHA1
    [oauth_timestamp] => 1370895219
    [oauth_version] => 1.0
    [oauth_token] => xxxxxxxxxksvCEU4aneGUu13Pe1UQ
    [oauth_signature] => xxxxxxxxxORWpPyrk4%3D
)
REQUEST params: 

Array
(
    [delimited] => length
    [follow] => 18647765
)

I have been using these keys, tokens to post to the Twitter API. I tsted this by posting to our page using our token and keys. See attached. The creds work.

3. Make sure that your server clock is within 5 minutes of the Twitter server. You can use the api console with any API call to see the Twitter server time. http://140dev.com/twitter-api-console/

Returned from the test screen suggested:

[date] => Mon, 10 Jun 2013 16:12:46 GMT

In my request:

oauth_timestamp="1370895219"

1370895219 = 4:13 pm, which is correctish (It took me a minute to paste it over)

That seems to be right as well, unless I'm missing something.

Attached are my PHP scripts and the full phirehose console response. My equivalent of get_tweets.php is TwitterStreamJob.php.

Any thoughts?

Thanks so much!

Matt W.


blive_post.png
phirehose_debug.zip

Matt Walsh

unread,
Jun 10, 2013, 1:07:15 PM6/10/13
to 140dev-twitt...@googlegroups.com, ad...@140dev.com
One more thing. Not sure if it's meaningful, but I have my own class that consumes using basic auth that works just fine.

Thanks,
M

Miguel Jesús Fernández López

unread,
Jul 18, 2013, 7:28:52 PM7/18/13
to 140dev-twitt...@googlegroups.com, ad...@140dev.com
Hey, did you find what was happening?
I am stuck with the same issue… :/

Thanks

Matt Walsh

unread,
Jul 18, 2013, 7:45:48 PM7/18/13
to 140dev-twitt...@googlegroups.com
Miguel--

I'm not sure what the problem was. In the end, a found a simpler class that I modified to be a little more flexible. Here's what I am using, which works well and is ultra simple. You could probably modify it to do whatever you want. I had to pull out some of our app-specific functions and I haven't tested it, but this is in production and does work. 

Matt


--
You received this message because you are subscribed to a topic in the Google Groups "140dev Twitter Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/140dev-twitter-framework/SKEeMAhFiFc/unsubscribe.

To unsubscribe from this group and all its topics, send an email to 140dev-twitter-fra...@googlegroups.com.
twitter_stream_example.php
TwitterStreamOauth.php

Miguel Jesús Fernández López

unread,
Jul 19, 2013, 11:49:43 AM7/19/13
to 140dev-twitt...@googlegroups.com
Matt,

Thanks for your quick message! I really appreciate this because I am a little bit lost with this.

I've just added my oauth details and now I have a 503 error, I am not sure if I am doing something wrong:


$config['twitter']['consumerKey'] = "*******************";
$config['twitter']['consumerSecret'] = "*******************";
$config['twitter']['oauth_token'] = "*******************";
$config['twitter']['oauth_token_secret'] = "*******************";
$stream = new TwitterStreamOauth($config['twitter']['consumerKey'], $config['twitter']['consumerSecret'], $config['twitter']['oauth_token'], $config['twitter']['oauth_token_secret']);
$params = array();
$params['track'] = array('morning', 'goodnight', 'hello', 'the', 'and'); //keywords
$params['follow'] = '';//user ids
$stream->setParams($params);
$stream->start(); 

Do you see anything wrong?

REQ DATA: follow=&language=en&track=morning%2Cgoodnight%2Chello%2Cthe%2Cand
Array
(
    [track] => morning,goodnight,hello,the,and
    [follow] => 
    [language] => en
    [oauth_consumer_key] => *******************
    [oauth_nonce] => *******************
    [oauth_signature_method] => HMAC-SHA1
    [oauth_timestamp] => 1374248699
    [oauth_token] => *******************
    [oauth_version] => 1.0
)

follow=&language=en&oauth_consumer_key=*******************&oauth_nonce=*******************&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1374248699&oauth_token=*******************&oauth_version=1.0&track=morning%2Cgoodnight%2Chello%2Cthe%2Cand
BASE STRING: 
POST&https%3A%2F%2Fstream.twitter.com%2F1.1%2Fstatuses%2Ffilter.json&follow%3D%26language%3Den%26oauth_consumer_key%*******************%26oauth_nonce%*******************%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1374248699%26oauth_token%3D*******************%26oauth_version%3D1.0%26track%3Dmorning%252Cgoodnight%252Chello%252Cthe%252Cand
REQUEST : 
POST /1.1/statuses/filter.json HTTP/1.1
Host: stream.twitter.com
Authorization: OAuth oauth_consumer_key="*******************", oauth_nonce="*******************", oauth_signature="*******************", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1374248699", oauth_token="*******************", oauth_version="1.0"
Content-Length: 65
Content-Type: application/x-www-form-urlencoded


follow=&language=en&track=morning%2Cgoodnight%2Chello%2Cthe%2Cand
ERROR: HTTP/1.1 503 Service Unavailable

Thanks in advance,
Miguel

To unsubscribe from this group and all its topics, send an email to 140dev-twitter-framework+unsub...@googlegroups.com.

Matt Walsh

unread,
Jul 19, 2013, 11:57:54 AM7/19/13
to 140dev-twitt...@googlegroups.com
Take a look at this:


If you can't get it going I will take a look in depth. 


To unsubscribe from this group and all its topics, send an email to 140dev-twitter-fra...@googlegroups.com.

Miguel Jesús Fernández López

unread,
Jul 19, 2013, 1:13:27 PM7/19/13
to 140dev-twitt...@googlegroups.com
I left the script running and now it works, I think it was a temporally issue.

Thanks a lot though!

To unsubscribe from this group and all its topics, send an email to 140dev-twitter-framework+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Matt Walsh

unread,
Jul 19, 2013, 1:15:25 PM7/19/13
to 140dev-twitt...@googlegroups.com
Any time.


To unsubscribe from this group and all its topics, send an email to 140dev-twitter-fra...@googlegroups.com.

John

unread,
Aug 23, 2013, 10:16:49 AM8/23/13
to 140dev-twitt...@googlegroups.com, ad...@140dev.com
I'm seeing what may be the server clock being out of sync with the Twitter server, however, this isn't a constant thing.  I haven't had any problems with it until two days ago where I received the 401 error for I believe it was 13 hrs straight.  then I stopped receiving the error and the connection to the twitter server was successful and everything was golden.  Then yesterday I had the same issue for a span of 2 hours before the problem resolved itself.  since I'm able to connect the rest of the time, and since this is a persistent process I'm very certain that the OAuth items are correct.  I have checked and am fairly certain that there was not another get_tweets.php script running.  If this is indeed an out of sync server clock, what can be done to make sure the two clocks are in sync?  Preferably without having to be physically logged into the machine and manually fixing things.

I'm going to double check that I do indeed have the most up to date version of your framework, but I'm fairly certain it is.

Thank you for your time,

-John

Adam Green

unread,
Aug 23, 2013, 10:29:47 AM8/23/13
to 140dev-twitt...@googlegroups.com
You should ask your webhost for the best method for doing this, but there are certainly ways to set a cron job that synchs with a remote time server. I let my sysadmin handle those types of details. 


--
You received this message because you are subscribed to the Google Groups "140dev Twitter Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 140dev-twitter-fra...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages