I am getting the same excact problem. I have tried to debug it but with no success.
If I use my browser I get a session ID and and can send message through my browser with a link, so my parameters (api_id, password etc) are correct.
Anyone solve this problem???
If I manage to solve it. I will post.