Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Code 220 - "Your credentials do not allow access to this resource" When tryig to get retweets

When i try to get https://api.twitter.com/1.1/statuses/retweets/21947795900469248.json with my authorized credentials (oauth), i'm getting:

{
 "errors": [
  {
   "message": "Your credentials do not allow access to this resource",
   "code": 220
  }
 ]
}

error: Any other twit id's not working. Is there a problem with this endpoint? Because i was getting true response until yesterday. Something changed?

like image 243
hardc0der Avatar asked Apr 29 '14 05:04

hardc0der


People also ask

Why is twitter API not working?

There was a problem authenticating your request. This could be due to missing or incorrect authentication credentials. This may also be returned in other undefined circumstances. Check that you are using the correct authentication method and that your credentials are correct.

What does Forbidden mean on twitter?

Forbidden. The request is understood, but it has been refused or access is not allowed. An accompanying error message will explain why. This code is used when requests are being denied due to update limits .


2 Answers

I experienced same issue with getting error code 220. Fix in my case was to prompt user to enter it's Twitter password again.

Check sample code below:

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                            requestMethod:SLRequestMethodPOST
                                                      URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"]
                                               parameters:@{@"status": tweetString}];

[request setAccount:account];  
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

   if ([responseData isKindOfClass:[NSData class]]) {

       NSError *jsonError = nil;
       NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&jsonError];

       if (json) {
           NSArray *errors = json[@"errors"];
           if (errors.count) {

               NSUInteger errorCode = [json[@"errors"][0][@"code"] integerValue];
                   if (errorCode == 220) {

                       ACAccountStore *accountStore = [[ACAccountStore alloc] init];
                       [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error2) {
                            NSLog(@"Renew result: %ld, error: %@", (long)renewResult, error2);

                            if (renewResult == ACAccountCredentialRenewResultRenewed) {
                                [self __makeTweetWithAccounts:@[account] rating:rating review:review];
                             }
                        }];
                }
            }
        }
    }             
    NSLog(@"Twitter response data: %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}]; 
like image 190
Josip B. Avatar answered Sep 20 '22 19:09

Josip B.


Was getting the same error when I noticed I was using GET instead of POST. Changed it and it worked.

like image 24
pbeaumier Avatar answered Sep 17 '22 19:09

pbeaumier