REST API POST Requests via Fabric iOS

ios
rest

#1

Hello,

I’m using fabric 1.14 on my iOS app.
I’m logged in and GET Requests work flawlessly.
But POST Requests always return me this error:

Error: Error Domain=TWTRNetworkingErrorDomain Code=-1011 "Request failed: unauthorized (401)" UserInfo={NSLocalizedFailureReason=, NSErrorFailingURLKey=https://api.twitter.com/1.1/favorites/create.json, NSLocalizedDescription=Request failed: unauthorized (401)}

Regarding that my user is authenticated, what is causing this rejection form twitter’s server ?

My code here:

NSString *userID = [Twitter sharedInstance].sessionStore.session.userID;
TWTRAPIClient *client = [[TWTRAPIClient alloc] initWithUserID:userID];
NSError *clientError;
NSURLRequest *request = [client URLRequestWithMethod:method URL:baseURL parameters:params error:&clientError];
if (request) {
    [client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (data) {
            // handle the response data e.g.
            NSError *jsonError;
            NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
            callback(@[[NSNull null], json]);
        }
        else {
            NSLog(@"Error: %@", connectionError);
            callback(@[connectionError.localizedDescription, [NSNull null]]);
        }
    }];
}
else {
    NSLog(@"Error: %@", clientError);
    callback(@[clientError.localizedDescription, [NSNull null]]);
}

#2

Was your app’s twitter consumer key created on apps.twitter.com or via Fabric?


#3

Yes, it is like this in info plist:

But my fabric app ACCESS LEVEL is set to READ. Is it the problem ?


#4

It should be fine, but can you email your Twitter consumer key to support(at)fabric(dot)io so that I can check on it’s permissions?

Also, just to be sure you’re not overriding that key when you initialize Fabric?


#5

Thanks for your feedback: I’ve sent you an email.
About overriding the key, I don’t think so…

Edit: I do override the key !! Let me try without it


#6

That’s the likely issue - let me know how it goes!


#7

Having the same problem with iOS swift, how would I know if I’m overriding my twitter key when initialising fabric?


#8

@chloeemullann Take a look at your info.plist and check if you see a Twitter Consumer Key present. Then also, check your code for something like this:

Twitter.sharedInstance().startWithConsumerKey("your_key", consumerSecret: "your_secret")
Fabric.with([Twitter.self()])