Send direct messages using the twitter API

I'm trying to use the twitter API to send direct messages using C #, but Twitter keeps saying:

"The remote server returned an error: (401) Unauthorized."

But it doesn't make sense, because I could have used other API calls where I was logged in.

Some background information:

I created an application with these permissions: direct, direct and direct messages

I could successfully post the status to my timeline:

https://dev.twitter.com/docs/api/1/post/statuses/update

I could as well get all direct messages sent to me:

https://dev.twitter.com/docs/api/1/get/direct_messages

The problem is trying to send a direct message:

https://dev.twitter.com/docs/api/1/post/direct_messages/new

0


source to share


2 answers


I couldn't figure out what happened yet, but I could make it work with an open source called tweetsharp. You can download it and see the code that works:

Tweet Sharp



Here is some sample code

    var service = new TwitterService(consumerKey, consumerSecret, accessToken, accessTokenSecret);
var user = service.VerifyCredentials();
var result = service.SendDirectMessage(recipient, message);

      

+2


source


Have you verified that you are following the message recipient and that they are following you? It must be this way before you can hide the person.



+1


source







All Articles