私はここで非常に苦労しています。私のアプリケーションには、STTwitter が成功する部分と、何も返さない (同じコードを使用する) 別の部分があります。
動作しない部分: `
-(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++;
}
}
}];
}
}
} `
機能する部分:
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);
}];
ありがとう!