SLRequest - Twitter returns code 215 (Bad authentication data)

喜你入骨 提交于 2019-12-09 18:34:07

问题


I have application with upload photo like in Instagram app. First my app uploads photo and returns link. Then sends link in status message. When I'm testing on my iPhone everything is ok, but when I'm testing on another iPhone then twitter return code 215 bad authentication data. Any ideas what could be wrong? Thx for reply.

- (void)tweet:(NSString *)identifier withCompletionHandler:(void (^)())completionHandler {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];

// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
    if(granted) {
        if (identifier) {
            // Get the list of Twitter accounts.
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

            if ([accountsArray count] > 0) {
                // Grab the initial Twitter account to tweet from.
                NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"];
                NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Check out this great flick on BLA BLA %@", [BLA_URL stringByAppendingFormat:@"/%@/%@", @"flick", identifier]]
                                                                 forKey:@"status"];

                SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                                        requestMethod:SLRequestMethodPOST
                                                                  URL:url
                                                           parameters:dict];
                [request setAccount:[accountsArray lastObject]];
                [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                    if ([urlResponse statusCode] == 200) {
                        NSLog(@"TWEEET!");

                    }
                    else { 
                        NSError *jsonError;
                        id data = [NSJSONSerialization JSONObjectWithData:responseData
                                                                  options:NSJSONReadingMutableLeaves
                                                                    error:&jsonError];

                        dispatch_async(dispatch_get_main_queue(), ^{
                            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter response"
                                                                                message:[NSString stringWithFormat:@"%d S: %d %@", [error code], [urlResponse statusCode], data]
                                                                               delegate:self
                                                                      cancelButtonTitle:@"Ok"
                                                                      otherButtonTitles:nil];
                            NSLog(@"NOOO TWEEET!");
                            [alertView show];
                            completionHandler();
                        });
                    }
                }];
...

And Pre-checking function:

- (IBAction)twitterButtonTapped:(id)sender {
if ([self.twitterButton isSelected]) {
    [self.twitterButton setSelected:NO];
}
else {
    [self.twitterButton setSelected:YES];

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
        if (!granted) {
            [self.twitterButton setSelected:NO];

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter access"
                                                                message:@"Please make sure you have allowed twitter for BLA BLA in your Settings."
                                                               delegate:self
                                                      cancelButtonTitle:@"Ok"
                                                      otherButtonTitles:nil];
            [alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];
        }
    }];
}

}


回答1:


Ok, I've got the answer! Problem was that other iPhone has incomplete account data - meanings you have to has filled username and password in your Settings app.



来源:https://stackoverflow.com/questions/19081530/slrequest-twitter-returns-code-215-bad-authentication-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!