401 error, Timestamp out of bounds


#1

I developed a client app using twitter4j, it running well for several months.
But today, I got the following error, what is the reason? I have run ntpdatetime.nist.gov on the server.

401:Authentication credentials ( http://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid conumer key cret, access token cret, and the system clock in in sync.
error - Timestamp out of bounds
request - /1/account erify_credentials.json?include_entities=false
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=6f0f59ca or
http://www.google.co.jp/search?q=3f8a87d4
TwitterException{exceptionCode=[6f0f59ca-3f8a87d4], statusCode=401, retryAfter=0, rateLimitStatus=null, version=2.2.0}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:93)
at twitter4j.TwitterBaseImpl.fillInIDAndScreenName(TwitterBaseImpl.java:131)
at twitter4j.TwitterImpl.verifyCredentials(TwitterImpl.java:1150)
at com.xinlab.blueapple.twitterrobot.ConvertRobot$1.run(ConvertRobot.java:77)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Failed to get mentions: 401:Authentication credentials ( http://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid conumer key cret, access token cret, and the system clock in in sync.
error - Timestamp out of bounds
request - /1/account erify_credentials.json?include_entities=false


#2

Well, my application show me the exactly same error messages. Help me too…


#3

I do have the same problam I have checked every thing the consumerkey/consumerSecret ,
AccessToken /AccessTokenSecret all are according the web page mention but posting tweet gives this exception.


#4

This error cause time on your server is not equal with time on twitter server, please re-config your time.


#5

Thanks a lot! I just changed the server’s date and everything worked just fine.


#6

Hello,

man how do you manage to change the server’s date?


#7

It depends on the server environment you are in.

An alternative to setting the system clock is to occasionally send a HTTP HEAD request to Twitter’s help/test end point. Within the response will be a HTTP Date header indicating Twitter’s server time. If you compare that time to the current time on your machine and then regularly adjust your oauth_timestamp values by the difference, you can stay synced to Twitter’s time without adjusting your clock.


#8

I am using windows 7, the date time format is UTC where as twitter return the datetime as GMT.
updated the date time even as in twitter server even then I am getting the same issue( oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Server returned HTTP response code: 401 for URL: http://twitter.com/oauth/request_token).Can any one please suggest me to fix this issue.


#9

thanks u so much


#10

Hello Sir,

I think oauth signature is based upon server time, but to change it as we are on shared hosting and if we change the time of server it will affect other projects, please let us know the solution

waiting for reply.


#11

Think about the problem a little differently – it’s not that you necessarily need to set the clock to a different time, you just need to account for its drift in all your time calculations. When you issue a request to the API (perhaps consider using a HEAD request https://api.twitter.com/1/help/test.json ) you’ll get back a “Date” HTTP header like:

Date: Tue, 07 Feb 2012 15:43:53 GMT

Convert that timestamp to epoch time and compare to your system current epoch time. The difference in seconds between the two is right about where you want to adjust your current timestamps to.

I’d do this process no more than once or twice a day to keep in sync.


#12

Hi, I can know how you solved your problem with the error: “timestamp out of bounds”


#13

Hey,
can you tell me, where and how I have to adjust my timestamps?
So, I found out that my system time is 2 hours (7200 seconds) later than Twitter’s server time.
Then, in OAuth.php I changed the function:
private static function generate_timestamp() {
return time()-7200;
}

But there is still a 401 error. I did a print_r($twitteroauth):

TwitterOAuth Object ( [http_code] => 401 [url] => https://api.twitter.com/oauth/request_token?oauth_callback=http%3A%2F%2Flocalhost.com%2Ftwitter_oauth.php&oauth_consumer_key=YOUR_CONSUMER_KEY&oauth_nonce=4aa1e48d49d6e7c1cd29fe6d56177e6d&oauth_signature=R4CGaWla%2BDXZyZvEy9zn5AmD9wA%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1336677397&oauth_version=1.0 [host] => https://api.twitter.com/1/ [timeout] => 30 [connecttimeout] => 30 [ssl_verifypeer] => [format] => json [decode_json] => 1 [http_info] => Array ( [url] => https://api.twitter.com/oauth/request_token?oauth_callback=http%3A%2F%2Flocalhost.com%2Ftwitter_oauth.php&oauth_consumer_key=YOUR_CONSUMER_KEY&oauth_nonce=4aa1e48d49d6e7c1cd29fe6d56177e6d&oauth_signature=R4CGaWla%2BDXZyZvEy9zn5AmD9wA%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1336677397&oauth_version=1.0 [content_type] => text/html; charset=utf-8 [http_code] => 401 [header_size] => 1007 [request_size] => 383 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.749927 [namelookup_time] => 0.020939 [connect_time] => 0.192984 [pretransfer_time] => 0.546367 [size_upload] => 0 [size_download] => 44 [speed_download] => 58 [speed_upload] => 0 [download_content_length] => 44 [upload_content_length] => 0 [starttransfer_time] => 0.749661 [redirect_time] => 0 [certinfo] => Array ( ) ) [useragent] => TwitterOAuth v0.2.0-beta2 [sha1_method] => OAuthSignatureMethod_HMAC_SHA1 Object ( ) [consumer] => OAuthConsumer Object ( [key] => YOUR_CONSUMER_KEY [secret] => YOUR_CONSUMER_SECRET [callback_url] => ) [token] => OAuthConsumer Object ( [key] => [secret] => [callback_url] => ) [http_header] => Array ( [date] => Thu, 10 May 2012 21:16:37 GMT [status] => 401 Unauthorized [cache_control] => no-cache, no-store, must-revalidate, pre-check=0, post-check=0 [expires] => Tue, 31 Mar 1981 05:00:00 GMT [x_frame_options] => SAMEORIGIN [x_mid] => 03dd10643046a5224f77eb09e3d711b0622fff2d [last_modified] => Thu, 10 May 2012 21:16:37 GMT [content_length] => 44 [x_transaction] => 5e13a55124acec3c [content_type] => text/html; charset=utf-8 [x_runtime] => 0.01498 [pragma] => no-cache [set_cookie] => _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCNNSnDg3ASIKZmxhc2hJQzonQWN0aW9uQ29u%250AdHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7ADoHaWQiJWYz%250AMTM3YTRkODgwZjljYjA3Y2EyNDI4YzgyNTMxMGUz–28c7efc422f3071cedc5d7ecc65f4fcf8a9503e7; domain=.twitter.com; path=/; HttpOnly [vary] => Accept-Encoding [server] => tfe ) )

And my system timestamp was: 1336684598

Do you have an idea what to do now?


#14

Are you purposely obscuring your consumer key and secret in that request, or are those values actually being sent as YOUR_CONSUMER_SECRET ?


#15

Sorry, i am new in this. Exactly how can i adjust the oauth_timestamp values?.. The code goes like this:

$defaults = array("oauth_version" => OAuthRequest::$version, "oauth_nonce" => OAuthRequest::generate_nonce(), "oauth_timestamp" => OAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key);

private static function generate_timestamp() {
return time();
}

Im unable to change the server time because its not mine. I would appreciate any help you could give me…


#16

header(“Expires: Mon, 26 Jul 1997 05:00:00 GMT”);
header(“Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0”);
header(“Pragma: no-cache”);
header(“Last-Modified:”.gmdate(“D, d M Y H:i:s”)." GMT");
header(‘Content-Type: text/html; charset=utf-8’);


#17

i have problem in 401 error using php

pls help me


#18

Same problem here, I can search, can get my timeline, but I can’t update my status using processing…
Getting this error:

TwitterException{statusCode=401, retryAfter=0, rateLimitStatus=null} Status code: 401


#19

Check if you have special chars like íñó


#20

If your problem is with tildes replace with the equivalent with entities numbers from here http://www.texaswebdevelopers.com/examples/xmlentities/xml_entities.asp