首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >STTwitter不返回成功或错误的任何内容

STTwitter不返回成功或错误的任何内容
EN

Stack Overflow用户
提问于 2014-11-17 21:08:24
回答 1查看 193关注 0票数 0

我在这里过得很艰难。在我的应用程序中,有一部分STTwitter是成功的,另一部分(使用相同的代码)没有返回任何内容。

不起作用的部分:`

代码语言:javascript
复制
-(IBAction)followTwitter:(id)sender {

if ([[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_on_file" ] == nil) {

    UIAlertView *allert = [[UIAlertView alloc] initWithTitle:@"Uh oh!" message:@"You have not linked your twitter account quite yet! Head to My Account settins to do so." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
    [allert show];

} else {
    ACAccountStore *store1 = [[ACAccountStore alloc] init];
    ACAccountType *twitterAccountType = [store1 accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    if ([twitterAccountType accessGranted]) {
        [store1 requestAccessToAccountsWithType:twitterAccountType options:nil completion:^(BOOL granted, NSError *error) {

            arrayOfUsernames = [[NSMutableArray alloc] init];

            iosAccounts = [store1 accountsWithAccountType:twitterAccountType];
            for (ACAccount *accou in iosAccounts) {
                [arrayOfUsernames addObject:accou.username];
            }

            NSString *usernameOnFile =  [[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_on_file" ];
            int tracker = 0;

            for (NSString *username in arrayOfUsernames) {

                if ([username isEqualToString:usernameOnFile]) {
                    NSLog(@"Using twitter account: %@", username);
                    STTwitterAPI *twitterAPI = [STTwitterAPI twitterAPIOSWithAccount:iosAccounts[tracker]];
                    [twitterAPI verifyCredentialsWithSuccessBlock:^(NSString *username) {
                        NSLog(@"Successfully authenticated the user");

                    } errorBlock:^(NSError *error) {

                        NSLog(@"Erorr: %@", error);

                    }];
                    NSLog(@"Twitter API: %@", twitterAPI);

                    [twitterAPI postFriendshipsCreateForScreenName:@"kickscaterer" orUserID:nil successBlock:^(NSDictionary *befriendedUser) {

                        NSLog(@"Befriend %@", befriendedUser);


                    } errorBlock:^(NSError *error) {

                        NSLog(@"Error: %@", error);
                    }];
                } else {
                    tracker++;
                }
            }
        }];
    }
}

}`

真正起作用的部分:

代码语言:javascript
复制
  STTwitterAPI *twitter= [STTwitterAPI twitterAPIOSWithAccount:iosAccounts[indexForAlert.row]];

        [twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
            // ...
            NSLog(@"Username: %@", username);
            //  [self.tableView reloadData];


            [[NSUserDefaults standardUserDefaults] setObject:twitter.userName forKey:@"twitter_on_file"];

        } errorBlock:^(NSError *error) {
            NSLog(@"Error: %@", error);
            // ...
        }];

        [twitter postFriendshipsCreateForScreenName:@"didi4" orUserID:nil successBlock:^(NSDictionary *befriendedUser) {

            NSLog(@"Befriend %@", befriendedUser);


        } errorBlock:^(NSError *error) {

            NSLog(@"Error: %@", error);
        }];

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2014-11-17 21:37:04

postFriendshipsCreateForScreenName:方法应该在成功块中调用,与日志"Successfully user“处于同一级别。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26973436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档