試試這個代碼,你可以得到你所期待的東西,
-(void) followUsOnTwitter {
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:@"abcd" forKey:@"screen_name"]; // Change the Value String
[tempDict setValue:@"true" forKey:@"follow"];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.json"]
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);
if (urlResponse.statusCode == 200)
{
// follow by usr
}
}];
}
}
}];
}
的錯誤是「壞的認證數據」 - 你有沒有正確註冊你的應用程序,並得到您的認證令牌? –
特倫斯伊登謝謝你的回覆。我用這個方法http://stackoverflow.com/questions/8085055/how-to-follow-people-with-the-new-twitter-api-in-ios-5,它工作正常。 –