Getting a "You cannot send messages" when posting a Tweet

restapi
ruby
error-codes

#1

I am using the REST API (via the twitter rails gem) to post tweets from my app. 99% of the time this works fine, however, now and then I am getting this error message: “You cannot send messages to users who are not following you” This is super strange as I am not sending any direct messages. Here’s my code:

 begin
      client.update_with_media(tweet, file)
      rescue Twitter::Error::Forbidden => e
        raise "Twitter::Error::Forbidden #{e.message}."
      end
end

Has anyone seen this?


#2

Does the status text in the failing messages being with "M " or "D " - that would cause them to be interpreted as direct messages.


#3

Yes, you are right! The tweet began with a name “M. Praince”. How do you suggest I mitigate the issue? Is there a way to format the text so it is not confused with the direct message.


#4

I think if you prefixed it with a space or a dot it might be ok? I’m not certain though.


#5

Thanks! I will play around with different solutions!