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



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:

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

Has anyone seen this?


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


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.


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


Thanks! I will play around with different solutions!