这是我的“关注推特”(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)"
)
答案 0 :(得分: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)
这表明无效的身份验证,即使上面的代码看起来与我在每个教程/示例中看到的代码完全相同。我想我会再创一个问题......