Thursday, 12 September 2013

iOS : Post on twitter without open dialogue using twitter.framework

iOS : Post on twitter without open dialogue using twitter.framework

I am trying to posting a tweet on twitter using iOS twitter.framework ,
somehow its not showing me any error when post request gets done, however
its not posting anything on twitter!
Here's my code for
-(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]]);
}
}];
}
}
}];
}
Inside the block, I am not getting any error, but I got to print this,
2013-09-12 19:51:40.103 MyApp[8380:21603] Twitter response, HTTP response:
410
2013-09-12 19:51:44.053 MyApp[8380:21603] Message no longer exists
It's not logged any error message!
Note,
1) I'd already configured a twitter account in the settings.
What's wrong? I am missing something?

No comments:

Post a Comment