[iOS] 401 unauthorized error when using square brackets


#1

I’m working on the first iOS application using Fabric.
I want to implement post tweet. (using “POST /statuses/update.json” endpoint)

Part of implementation is as below.

NSString *endpoint = @"https://api.twitter.com/1.1/statuses/update.json";
NSDictionary *parameters = @{@"status":@"I went to [Central Park]"};

TWTRAPIClient *client = [[Twitter sharedInstance] APIClient];
NSURLRequest *request = [client URLRequestWithMethod:@"POST"
                                                 URL:endpoint
                                          parameters:parameters
                                               error:nil];
[client sendTwitterRequest:request
                completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                    if (connectionError) {
                        NSLog(@"Error: %@", connectionError);
                        return;
                    }
                    
                    NSLog(@"Result : %@", data);
                }];

When I use square brackets ([ and ]), request failed.
Description of NSError object is as below.

Error Domain=TwitterAPIErrorDomain 
Code=32 "Request failed: unauthorized (401)" 
UserInfo=0x7fd13e56e4d0 {NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/update.json, NSLocalizedDescription=Request failed: unauthorized (401), NSLocalizedFailureReason=Twitter API error : Could not authenticate you. (code 32)}

But, When I don’t use square brackets, request succeeded.

Is Using square brackets forbidden? :scream:


[iOS] 401 unauthorized error when using brackets
#2

Thank you for pointing out square bracket!!! You just saved my day.
I have same issue, and I was looking for wrong place wondering what I’ve done wrong on authentication…
As you pointed out, it’s the square bracket in the message. This’s kind of silly bug. Will there be a quick fix?


#3

Hey guys, thanks for reporting this. This is def an issue and we’ll fix it.

V


#4

Hi Val, do you have any timeframe for this fix? Also, I cannot find how to get version number of current TwitterKit (installed through Fabric) :frowning:


#5

No timeframe as of yet. You can right click > Get Info on TwitterKit.framework file to see the version.


#6