我正在尝试使用iOS twitter.framework
在Twitter上发布推文,不知何故,当发布请求完成时它没有显示任何错误,但是 它没有在Twitter上发布任何内容!
这是
的代码-(void)twitPost
{
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if (!arrayOfAccounts)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Twitter Account" message:@"There are no Twitter accounts configured. You can add or create a Twitter account in the main Settings section of your phone device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
return;
}
// Request access from the user to access their Twitter account
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
// Did user allow us access?
if (granted == YES)
{
// Populate array with all available Twitter accounts
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
// Keep it simple, use the first account available
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:@"This is a sample message!" forKey:@"status"] requestMethod:TWRequestMethodPOST];
[postRequest setAccount:acct];
// Perform the request created above and create a handler block to handle the response.
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if(error)
{
NSLog(@"Twitter Request failed with error: %@",[error localizedDescription]);
}else{
NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
NSLog(@"Message %@",[NSHTTPURLResponse localizedStringForStatusCode:[urlResponse statusCode]]);
}
}];
}
}
}];
}
在街区内,我没有收到任何错误,但我得打印出来,
2013-09-12 19:51:40.103 MyApp [8380:21603] Twitter回复,HTTP回复:410
2013-09-12 19:51:44.053 MyApp [8380:21603]消息不再存在
没有记录任何错误消息!
请注意,
1)我已经在设置中配置了一个推特账号。
更新
我尝试在浏览器中链接https://upload.twitter.com/1.1/statuses/update.json
并打印以下JSON响应!
{
errors: [
{
message: "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.",code: 68
}
]
}
怎么了?我错过了什么?是否有一种简单的方法可以迁移到新的API?
答案 0 :(得分:0)