Twitter API application only mode authentication

2020-05-06 13:05发布

问题:

I've tried to integrate the STTwitter framework (Github project) for interacting with the Twitter API 1.1.

After I've create an app in my dev account, I've used the OAuth credentials for application only mode authentication. Anyway, I get the following error and I don't know how to fix it: Error Domain=STTwitterTwitterErrorDomain Code=220 "Your credentials do not allow access to this resource"

STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:@"XXX"
                                             consumerSecret:@"XXX"];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {

    NSLog(@"Access granted with %@", bearerToken);


} errorBlock:^(NSError *error) {
    NSLog(@"-- error %@", error);
}];

Does anyone have a clue how to fix it?

回答1:

This is because you didn't use the right STTwitterAPI constructor.

Use [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:consumerSecret:] instead and your example will work fine.



回答2:

I got the same problem. However it was caused by the Twitter account on the device not being setup properly - the password field was empty. After I've fixed that I could communicate with Twitter without a problem!