[iOS] 401 unauthorized error when using break line character


I am new in Twitter Fabric. I post a new tweet by using the code below

NSString *endpoint = @"https://api.twitter.com/1.1/statuses/update.json";
NSDictionary *parameters = @{@"status":@"a \n b"};

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

It is working well if the message does not contain break line (’\n’)
And if the message contains (’\n’) I will got the error

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

I do not know why this happened, please help me
Thank you


@PhanVanLinhVN Is anything else changing other then the content of the message?


I just only send the message. and if I remove ‘\n’ it work


Thanks @PhanVanLinhVN, I’m looking into this with the team.


Does anyone from Twitter have an update on this? I too am getting a 401 error when sending a message with line breaks via https://api.twitter.com/1.1/direct_messages/new.json. As soon as I remove them the message sends ok.


@michaeljpetrie Yes, I do have an update and the underlying bug was resolved. You just need to update to version 2.2.0 - https://docs.fabric.io/apple/changelog.html#id35