我想向Twitter好友发送直接消息。我使用下面的代码(appdelegate.twitterAccount
是从iOS Twitter账号ACAccountStore
):如何使用iOS向Twitter好友发送直接消息
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
NSString *idString = @"123456789"; // should be some read user_id
NSString *urlString = @"https://api.twitter.com/1.1/direct_messages/new.json?";
NSURL *postDirectMessageRequestURL = [NSURL URLWithString:urlString];
NSDictionary *parameters = @{@"user_id": idString,
@"text": @"some text"};
SLRequest *postDirectMessageRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:postDirectMessageRequestURL
parameters:parameters];
postDirectMessageRequest.account = appdelegate.twitterAccount;
[postDirectMessageRequest performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *urlResponse, NSError *error) {
if (nil != error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"urlResponse: %@", urlResponse);
}
}];
不幸的是,我得到以下错误,虽然Twitter帐户设置正确iOS中:
Error Domain=kCFErrorDomainCFNetwork Code=-1012 "(null)" UserInfo={_kCFURLErrorAuthFailedResponseKey=<CFURLResponse 0x160352490 [0x19ebeb150]>{url = https://api.twitter.com/1.1/direct_messages/new.json?}}}, NSErrorFailingURLKey=https://api.twitter.com/1.1/direct_messages/new.json?}
所以,认证有问题,但是什么?