IOS- Twitter API error : Timestamp out of bound

restapi
ios
apps.twitter.com

#1

Hi everyone,

I created sample project for test a compose message by using REST API, but i got a problem.

This code i use for composing

    NSString *endpoint = @"https://api.twitter.com/1.1/statuses/update.json";
    NSError *error = nil;
    NSDictionary *parameters = @{@"status":@"test message"};
    TWTRAPIClient *client = [[TWTRAPIClient alloc] initWithUserID:[Twitter sharedInstance].sessionStore.session.userID];

    
    NSURLRequest *request = [client URLRequestWithMethod:@"POST"
                                                     URL:endpoint
                                              parameters:parameters
                                                   error:&error];

    [client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError) {
            NSLog(@"%@", connectionError);
            
        }else{
            NSLog(@"ok");
        }
    }];
  1. If i immediately set this code in “viewDidAppear” method, the progress will be success.

  2. If i set this code after 5 seconds, i will get error like this

2016-08-04 10:20:05.833 TestFabric[4750:945350] [Fabric] Unable to locate application icon
2016-08-04 10:20:10.653 TestFabric[4750:945373] Local time is off from UTC by 62735212799.346588 seconds
2016-08-04 10:20:11.651 TestFabric[4750:945377] Local time is off from UTC by 62735212799.348816 seconds
2016-08-04 10:20:11.653 TestFabric[4750:945350] Error Domain=TwitterAPIErrorDomain Code=135 "Request failed: unauthorized (401)" UserInfo={NSLocalizedFailureReason=Twitter API error : Timestamp out of bounds. (code 135), TWTRNetworkingStatusCode=401, NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/update.json, NSLocalizedDescription=Request failed: unauthorized (401)}

I use dispatch for delay 5 seconds

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
     .... above code ....
});

I’ve already see someone say just changed the server timezone, but i use Xcode, how can i change it ?
Thank for any helping!


#2

The warning printed out does indicate a very large disconnect between the current time and the time of your server or test device. I’d check the device settings you are testing on or reset your XCode’s simulator settings.


#3

Thank for reply, but i just created new project from Xcode and install Fabric + Twitter, it doesn’t have any code except twitter compose code above.


#4

I found some problems.

That code if i test on my simulator or iphone 5, it will be done, but my Iphone 6 will show error above. May be it only happen on some devices, i think that i belong to system.
Can you help me anything ?


#5

For the iPhone 6, what’s the time you see displayed when you’re testing?


#6

My iphone 6’s time is correct with other devices T____T


#7

In that case, it’s not clear to me why the device is reporting an older time.


#8

I found same problem, I try to set Calendar to Gregorian
(iPhone Setting>General>Language&Region>Calendar)
It 's work! :slight_smile: but This 's solution by user.

Now I try to log Http Header I found this
{
“Accept-Encoding” = gzip;
Authorization = "OAuth
oauth_timestamp=“3623568367”,
oauth_version=“1.0”,
…Etc.
}
*3623568367 -> Sat, 28 Oct 2084 10:46:07 GMT :open_mouth: It 's the future!
I try to change oauth_timestamp to now but I found same result. :unamused:


#9

Hey @SLS,

Sorry, but I’m having a bit of a hard time following, if you’re all set and sharing more information or if there is another issue you’re seeing.

-Mike


#10

:disappointed_relieved:

Ok, I just try to find a solution but the best way
I think to be fixed by twitter or have a better solution.

Testing Solution

  1. Change iPhone Setting Solution -> bad solution
  2. Change HTTP Header Solution -> not work*
  • Some http header can’t change. It 's unique parameter by generate for each unique request.

#11

Thanks @SLS, it can be difficult to track these down to the nature of the request. What was your calendar setting prior to that change? Maybe that’s the issue.


#12

@bonnell Please see my topic


#13

Closing this thread as it has spawned off in a bunch of different directions. I’ll reply to your other thread @SLS.

-Mike


#14