^ < > \ | ` tweets error




I’m using Fabric TwitterKit 2.4.0 in my app.
I’m trying to tweet statuses/update endpoint using the TWTRAPIClient. However when it includes the following characters, an error is returned.

^ < > \ | `

TWTRAPIClient *client = [[TWTRAPIClient alloc]initWithUserID:userID];

NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
parameters[@"status"] = @"^";
// When replacing the "^" to "%5E", "%5E" will be posted as it is.

NSURLRequest *request = [client URLRequestWithMethod:@"POST" URL:@"https://api.twitter.com/1.1/statuses/update.json" parameters:parameters error:nil];
[client sendTwitterRequest:request completion:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {

I get the following error

Error Domain=TwitterAPIErrorDomain Code=32 "Request failed: unauthorized (401)" UserInfo={NSLocalizedFailureReason=Twitter API error : Could not authenticate you. (code 32), TWTRNetworkingStatusCode=401, NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/update.json, NSLocalizedDescription=Request failed: unauthorized (401)}
  • I’m using the consumerKey and consumerSecret that has been generated by the Fabric, and I input it into info.plist.

  • I tried NSURLSession, it was the same failure.

  • When I used Social.framework, it succeeds.

What should I do?


TWTRComposer Swift 3 Fails to post tweet
When Am posting my tweet without special character it posting correctly but if string contain any special character it throw an exception 401
TwitterKit 401 error

Hey @67gmadb279,

Thanks for reaching out on this - is this only when you have a tweet that includes the specific full: “^ < > \ | `” or any one of those characters?



Thank you for your reply. It is the latter.


Thanks for confirming that, I’m curious - do you see the same error if you use the built-in composer? https://docs.fabric.io/apple/twitter/compose-tweets.html#present-configure-the-composer


The error does not return when I used the TWTRComposer.
It seems only to when I was using the generated by Fabric authorization.


Thanks @67gmadb279, I’ve flagged this to the team as an error, but don’t currently have an ETA on the fix.



I am facing same error. Any update?



I also confirmed this problem with TwitterKit 3.0.3. Tried to re-generate customer key and secret, but no change.


Why are you using the statuses/update endpoint rather than TWTRComposer? The user should be able to approve and modify the Tweet that is being sent.



Thank you for replying, the answer is that TWTRComposer is not flexible for I am expecting.

Do you have any workaround (except for TWTRComposer) to avoid this issue?



Also Confirmed same issue by TWTRAPIClient.sendTweet method that introduced in TwitterKit 3

Here is the reproducible code:

// client is TWTRAPIClient
client.sendTweet(withText: "^") { (tweet, err) -> Void in
  if err != nil {
    print("Error: \(String(describing: err))")


What is the issue with using the Tweet Composer? That is the intended way to implement Tweet sharing in Twitter Kit, so I’m confused what it is lacking for your use case.



TWTRComposer is also not working.


Thank you for clarifying.


I’m also suffering from this issue. Is there any plan to fix this issue?


This issue still occurs with TwitterKit 3.1.1 .
I found out that “\r” as another pattern to reproduce the bug.


This is a very big issue.
Twitter-Kit should add the legal characters to be escaped.
Or Twitter-Kit can leave URL encoding to our developer side.

I hope this issue will be resolved as soon as possible.



I’m also facing same issue.
Is there progress on this issue?


Facing the same issue, is there any way to fix this?


Twitter Developer Page hints that such Tweets are failing because parameter values should be converted to UTF-8 prior to sending the Tweet. Percent encoding will be a work-around till the new fix.

We are working on a fix for this since this is facing users (of the apps with Twitter Kit), and they shouldn’t worry about converting to percent encoding.
Thank you for your patience!