In the two links you mentioned they are using Twitter Api v1. which is deprecated a long time ago: API V1 no longer function instead you should be using the V1.1 so the url to post a tweet will be https://api.twitter.com/1.1/statuses/update.json
In addition TWRequest
is also deprecated in iOS 6.0 you should use SLRequest
Here is a simple code to do so:
- (void) sendTweetWithoutPromp:(NSString*) tweetText
{
NSString *url = @"https://api.twitter.com/1.1/statuses/update.json";
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:tweetText forKey:@"status"];
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if(granted)
{
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0)
{
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:TWRequestMethodPOST URL:[NSURL URLWithString:url] parameters:params ];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
NSLog(@"output = %@",output);
dispatch_async( dispatch_get_main_queue(), ^{
if (error)
{
}
});
}];
}
else
{
NSLog(@"no Account in Settings");
}
}
}];
}