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.";
}
);
}
user3648985
source
share