It's not different from telling apart US english and UK english
You must know both languages and seek for very specific differences. It's a tricky and not accurate way. Also you may need to get the context of the message to get the meaning of the words.
Even a native portuguese speaker can have hard time telling them appart, it's even worse for small texts.
To get an example get search for the same topic (example, Clinton x Trump debate) in brazilian and portuguese news sites and try to read them and see the diffrences. You will got an idea.
Also put in mind if you are getting casual chatting you will need to handle slangs, mispellings and region specific expressions from each country.
After reading how Guesslanguagew uses trigram analysis
I see it ill get abad time telling dialects apart. There are few words with different spelling.