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

5

8

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?

Urge answered 29/4, 2014 at 5:26 Comment(0)
O
3

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]);
}]; 
Obit answered 20/5, 2016 at 9:46 Comment(0)
J
1

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

Jetton answered 26/10, 2015 at 0:6 Comment(1)
Not worked- {"errors":[{"code":86,"message":"This method requires a GET or HEAD."}]}Ultramicrochemistry
E
0

Set app permissions to Read, write, and direct messages ...and Regenerate Access Token and Token Secret.

It worked for me

Earring answered 28/9, 2014 at 0:54 Comment(4)
Does not work for me. I created even a brand new app, but still get this issueAliquot
Twitter and Facebook are changing their APIs like socks, @Aliquot , it is annoying but keep that in mind and try the latest solutions first.Earring
@ManishGupta I recommend you look for answers from 2016, because Twitter and Facebook change their APIs as if they where socks xd.Earring
Yep.. Many thanks for getting back here:) Really appreciated.Ultramicrochemistry
A
0

I had similar problem with SLRequest class on iOS SDK7.1. Now to get retweets, or post retweet, i started to use deprecated class TWRequest. Just #import resource and use this method:

- (void)retweetMessageV2HavingId:(NSString*)messageId {
    NSString *retweetString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/retweet/%@.json", messageId];
    NSURL *retweetURL = [NSURL URLWithString:retweetString];
    TWRequest *request = [[TWRequest alloc] initWithURL:retweetURL parameters:nil requestMethod:TWRequestMethodPOST];
    request.account = self.account;

    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        if (responseData)
        {
            NSError *parseError = nil;
            id json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];

            if (!json)
            {
                NSLog(@"Parse Error: %@", parseError);
            }
            else
            {
                NSLog(@"%@", json);
            }
        }
        else
        {
            NSLog(@"Request Error: %@", [error localizedDescription]);
        }
    }]; }
Ashcraft answered 18/11, 2014 at 11:22 Comment(0)
U
0

I have generated access-tokens going to 'Keys and Access Tokens' tab in my current app page. Then, i have set 'Access Token' and 'Access Token Secret' for the access tokens for 'auth' obj that has permisson for the app to access in source code.

Uniformed answered 18/2, 2018 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.