Receiving 401 Unauthorized / Do I Need to Recreate My Access Token


My streaming Twitter application stopped working, and in the logs I see:

Phirehose: Connecting to twitter stream: with params: array ...
Phirehose: Authorization: OAuth realm=...
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 generated my consumer key/secret and access token/secret on June 13, and haven’t changed them since. My hosting did have to reboot my server over the weekend, so I had to restart my app. This is when I noticed the “Unauthorized” message. Nothing in my code change has changed.

Do I need to recreate my access token? Do these tokens expire?

In case it helps, I’m using the Phirehose library at:

Thank you!


Access tokens don’t generally expire unless you explicitly force them to.

I’d check other things that might be different on your server – is the server time synced with Twitter’s?


@episod, your reply resolved my issue.

As I mentioned, the only change was my server rebooting (which it has done before, each time without issue). However, per your reply, I checked my server time, and it was somehow five hours off. Since my server is a virtual private server (a VPS), I had speak with my hosting provider because ultimately they had to reset the time. Once they did that, my tokens began to work.

Thanks very much!