本文介绍了试图“跟随”有人在Twitter上使用新的iOS 5 API,获得406返回错误。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用新的iOS 5 API在Twitter上关注某人,获得406返回错误。为什么?

Trying to "follow" someone on Twitter using new iOS 5 API, getting 406 return error. Why?

我的代码是否正确?需要找出为什么这不起作用....

Is my code correct? Need to find out why this isn't working....

    - (void)followOnTwitter:(id)sender
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
    if(granted) {
        // Get the list of Twitter accounts.
        NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

        // For the sake of brevity, we'll assume there is only one Twitter account present.
        // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
        if ([accountsArray count] > 0) {
            // Grab the initial Twitter account to tweet from.
            ACAccount *twitterAccount = [accountsArray objectAtIndex:0];

            NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
            [tempDict setValue:@"sortitapps" forKey:@"screen_name"];
            [tempDict setValue:@"true" forKey:@"follow"];

            TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/friendships/create.format"] 
                                                         parameters:tempDict 
                                                      requestMethod:TWRequestMethodPOST];


            [postRequest setAccount:twitterAccount];

            [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                NSLog(@"%@", output);

                }];
            }
        }
    }];
}

所有代码看起来都是正确的。参数不正确吗?网址是否正确?需要一些方向....

All of the code looks correct. Are the parameters incorrect? Is the URL correct? Need some direction here....

推荐答案

找到我自己的问题的答案...我将URL更改为工作。

Found the answer to my own question... I changed the URL to https://api.twitter.com/1/friendships/create.json and it worked.

不要忘记它的https,而不仅仅是http。

Don't forget it's https, not just http.

这篇关于试图“跟随”有人在Twitter上使用新的iOS 5 API,获得406返回错误。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 04:28