TwitterKit Error attempting to like: Request failed: unauthorized (401) iOS

twitterkit

#1

I am showing tweets using fabric twitterkit iOS.
eg - // TODO: Base this Tweet ID on some data from elsewhere in your app

[[[TWTRAPIClient alloc] init] loadTweetWithID:@"732514364792639488" completion:^(TWTRTweet *tweet, NSError *error) {
    if (tweet) {

        TWTRTweetView *tweetView = [[TWTRTweetView alloc] initWithTweet:tweet style:TWTRTweetViewStyleRegular];
        tweetView.frame = CGRectMake(20, 20, 286, 518);
        tweetView.showActionButtons = YES;
        tweetView.theme = TWTRTweetViewThemeDark;
        tweetView.delegate = self;
        
        
        [self.view addSubview:tweetView];
        

    } else {
        NSLog(@"Tweet load error: %@", [error localizedDescription]);
    }
}];

Initially when I tap on like/favorite it takes me to login, once I login it takes me back to my app and the tweet is liked.
Now if I revoke access to my app from my twitter account, I keep on getting this error whenever I tap on like and doesn’t ask to authorize/login to the app.
[TwitterKit] Error attempting to like: Request failed: unauthorized (401)
Is there any way to have a call back or notification for this error in my controller? how do I handle this?
I am using Twitterkit version 2.0.2.


#2

I am having this same issue. My view controller looks like this:

@interface TwitterViewController ()
@property (nonatomic, strong) TWTRAPIClient *client;
@end

@implementation TwitterViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString *userID = [Twitter sharedInstance].sessionStore.session.userID;
    _client = [[TWTRAPIClient alloc] initWithUserID:userID];
    
    [self setDataSource:[TWTRListTimelineDataSource.alloc initWithListSlug:@"my-list-slug" listOwnerScreenName:@"MyUserName" APIClient:_client]];
}
@end

When I go to favourite a tweet, I see

[TwitterKit] Error attempting to like: Request failed: unauthorized (401)

I’m not sure what I’m missing?


#3

To answer my own question - what I was missing was the callback URL and the settings in my pList as described here: https://dev.twitter.com/twitterkit/ios/installation