本文介绍了试图“跟随"有人在 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 更改为 https://api.twitter.com/1/friendships/create.json 并且成功了.

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 返回错误.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 21:56