0

这是我的“关注 twitter”(iOS6+)代码:

-(IBAction)twitterFollow
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

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

            NSLog(@"twitter accounts: %@", accountsArray);

            if ([accountsArray count] > 0) {
                // Grab the initial Twitter account to tweet from.
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];

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

                //requestForServiceType

                SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1/friendships/create.json"] parameters:tempDict];
                [postRequest setAccount:twitterAccount];
                [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                    NSString *output = [NSString stringWithFormat:@"HTTP response status: %i Error %d", [urlResponse statusCode],error.code];
                    NSLog(@"%@error %@", output,error.description);

                    NSString *twitterErrorMessage = [error localizedDescription];

                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:kDefaultErrorText message:twitterErrorMessage delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [alert performSelectorOnMainThread:@selector(show)
                                            withObject:nil
                                         waitUntilDone:NO];
                }];
            }else{
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:kDefaultErrorText message:kTextMessageNoTwitter delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert performSelectorOnMainThread:@selector(show)
                                        withObject:nil
                                     waitUntilDone:NO];
            }

        }
    }];
}

这就是我得到的:

HTTP response status: 410 Error 0error (null)

我究竟做错了什么?

屏幕名称和帐户有效:

twitter accounts: (
    "type:com.apple.twitter\nidentifier: 2ABCDEC6-9D6B-1234-9AB7-847EB167B123\naccountDescription: @theuser\nusername: theuser\nobjectID: x-coredata://ABD5C87A-FB5D-464E-AF18-2C1123451123/Account/p13\nenabledDataclasses: {(\n)}\nenableAndSyncableDataclasses: {(\n)}\nproperties: {\n    fullName = theuser;\n    \"user_id\" = 147712345;\n}\nparentAccount: (null)\nowningBundleID:(null)"
)
4

1 回答 1

0

好吧,我通过使用 1.1 API 摆脱了 410 错误:

SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.json"] parameters:tempDict];

现在我收到 400 错误:

HTTP response status: 400 Error 0error (null)

这表明身份验证无效,即使上面的代码看起来与我在找到的每个教程/示例中看到的代码完全相同。我想我会提出另一个问题......

于 2013-09-06T22:27:04.337 回答