如何在Twitter上向朋友发送url

我怎样才能发送到iOS的Twitter朋友的URL。 我可以发送直接的消息,但它不允许我发送URL。

这里是我的代码向Twitter朋友及其工作发布Driying消息。

-(void)postMessageToFriend:(NSString *)ID withMessage:(NSString *)message { NotificatioName = notificationNameStr; ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) { if (granted && !error) { NSArray *accountsListAry = [accountStore accountsWithAccountType:accountType]; int NoOfAccounts = [accountsListAry count]; if (NoOfAccounts >0) { NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/direct_messages/new.json"]; twitterAccount = [accountsListAry lastObject]; NSDictionary *p =@{@"status":@"Posted",@"screen_name":ID, @"text":message}; SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url parameters:p]; [postRequest setAccount:twitterAccount]; [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResposnse, NSError *error){ if (error) { NSLog(@"error : %@",error); }else{ NSError *jsonError = nil; NSString * responseStr = [[NSString alloc] initWithData:responseData encoding:NSJSONWritingPrettyPrinted]; NSArray *friendsdata = [NSJSONSerialization JSONObjectWithData: [responseStr dataUsingEncoding:NSUTF8StringEncoding] options: NSJSONReadingMutableContainers error: &jsonError]; NSLog(@"response value is: %@ %d ",friendsdata,[urlResposnse statusCode]); } }]; } } }]; } 

但是,如果我尝试在我的消息中添加URL,则返回此错误

 { errors = ( { code = 226; message = "This request looks like it might be automated. To protect our users from spam and other malicious activity, we can't complete this action right now. Please try again later."; } ); } 

我认为这与你的代码无关,但与Twitter。 显然,他们不允许发送直接消息的链接。 https://support.twitter.com/articles/14606-posting-or-deleting-direct-messages

即使是来自官方Twitter客户端或其网站的用户,也无法做到这一点。 AFAIK,这是一个已知的问题,据说他们正在努力。 但是他们这么说已经很久了。

您的请求被Twitter拒绝,因为它与OS X消费者令牌签名,因为SLRequest所有实例都是。

如果您想直接发送邮件中的URL,则必须使用官方Twitter客户端的消费者令牌来签署您的请求。

这不能用SLRequest完成,但可以使用STTwitter等第三方库完成 。

这不是一个正确的答案,但我分享它。 在我的情况下,我必须在直接消息中分享我的应用程序的链接。 消息文本中带有url的消息不起作用,但可以与消息文本共享任何Twitter帐户的链接。 所以我为我的应用程序做了一个推特,并把链接放在那里。