{"message":"Could not authenticate you","code":32} in direct_messages/new.json


#1

Hello there!

I am a iOS app developer.
I would like to send the direct message to my followers.
I wrote the code as following.

NSString *sURL = @"https://api.twitter.com/1.1/direct_messages/new.json";
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"xxxxxxxxxx" secret:@"xxxxxxxxxx"];
OAToken *token = [[OAToken alloc] initWithKey:@"xxxxxxxxxxxx" secret:@"xxxxxxxxxxx"];
OAHMAC_SHA1SignatureProvider *signature = [[OAHMAC_SHA1SignatureProvider alloc] init];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:sURL] consumer:consumer token:token realm:nil signatureProvider:signature];
[request prepare];

[request setHTTPMethod:@"POST"];
NSString *postString = @"text=hello&screen_name=followername";
NSData *postBody = [postString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:postBody];
[request setValue:[NSString stringWithFormat:@"%d", postBody.length] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

NSURLResponse *response;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

I got {“errors”:[{“message”:“Could not authenticate you”,“code”:32}]} in data.
Can you help me?

Thanks
Wang.