iOS: публикация в твиттере без открытого диалога с использованием twitter.framework
Я пытаюсь опубликовать твит в твиттере, используя iOS twitter.framework
, как-то не показывать мне никакой ошибки, когда пост-запрос выполняется, но ничего не публикуется в твиттере!
Вот мой код для
-(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?
1 ответ
Вы используете Twitter API версии 1, которая устарела.
Новое задокументировано здесь https://dev.twitter.com/docs/api/1.1
Вы можете проверить сторонние библиотеки, такие как STTwitter, чтобы облегчить вашу работу.