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 に答える