I am using STTwitter demo app to post tweet and images to my twitter account from demo app after authorization.I am trying below :
- (void)setOAuthToken:(NSString *)token oauthVerifier:(NSString *)verifier {
[_twitter postAccessTokenRequestWithPIN:verifier successBlock:^(NSString *oauthToken, NSString *oauthTokenSecret, NSString *userID, NSString *screenName) {
_loginStatusLabel.text = [NSString stringWithFormat:@"%@ (%@) %@," , screenName];
STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:_consumerKeyTextField.text consumerSecret:_consumerSecretTextField.text oauthToken:_twitter.oauthAccessToken oauthTokenSecret:_twitter.oauthAccessTokenSecret];
[twitter verifyCredentialsWithUserSuccessBlock:^(NSString *username, NSString *userID){
[self.twitter postStatusesUpdate:@"test" inReplyToStatusID:nil latitude:nil longitude:nil placeID:nil displayCoordinates:nil trimUser:nil autoPopulateReplyMetadata:nil excludeReplyUserIDsStrings:nil attachmentURLString:nil useExtendedTweetMode:nil successBlock: ^(NSDictionary *status) {
NSLog(@"twitter post success");
}
errorBlock:^(NSError *error) {
NSLog(@"twitter post failed %@",error.localizedDescription);
}];
}
} errorBlock:^(NSError *error) {
_loginStatusLabel.text = [error localizedDescription];
NSLog(@"-- %@", [error localizedDescription]);
}];
}
Even simple tweet with postStatusesUpdate method is not posting to my twitter account.It always enter failure block(twitter post failed).The above method is called from appdelegate.
EDIT: I successfully post content in twitter using SLRequest but unable to login again to twitter using my app if not loggedin in twitter native app. Above code works for authorization to twitter but not posting content and SLRequest works for posting content but not authorization.Any idea?
I got the solutions so thought of posting here as an answer:
I used TWTRAPIClient and initialize it using userid.And called TWTRAPIClient sendTwitterRequest