How to send a URL to a friend on Twitter

How can I send the url to a twitter friend on iOS. I can send a direct message, but it does not allow me to send URLs.

Here is my code for sending a Drirect message to Twitter Friend and its work.

-(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]);

                    }
                }];
            }
        }
    }];
}

But if I try to add a URL to my message, than return this error to me

{
    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.";
        }
    );
}
+1
source share
3 answers

I think this has nothing to do with your code, but with Twitter. Apparently, they do not allow sending links to direct messages. https://support.twitter.com/articles/14606-posting-or-deleting-direct-messages .

Twitter -. AFAIK, , , , . .

+3

Twitter, OS X, SLRequest .

URL- , - Twitter.

SLRequest, , STTwitter.

0

This is not the correct answer, but I share it. In my case, I have to share the link of my application in a direct message. A message with a URL in the body of the message does not work, but a link to any Twitter account can be used in conjunction with the body of the message. So I made a twitter for my application and gave a link there.

0
source

Source: https://habr.com/ru/post/1526296/


All Articles