问题
I trying to use twitter API to send direct messages using C# but Twitter keeps saying:
"The remote server returned an error: (401) Unauthorized."
But this has no sense because I could use other API calls where I was authorized.
Some background info:
I created an application with these access permissions: Read, Write and Access direct messages
I could succesfully post a status in my timeline:
https://dev.twitter.com/docs/api/1/post/statuses/update
I could also retrieve all the direct messages sent to me:
https://dev.twitter.com/docs/api/1/get/direct_messages
The problem is when I try to send a direct message:
https://dev.twitter.com/docs/api/1/post/direct_messages/new
回答1:
I couldn't figure out yet what's wrong, but I could make it work using a open source project called tweetsharp. You can download it and see the code that works:
Tweet Sharp
here is a code example
var service = new TwitterService(consumerKey, consumerSecret, accessToken, accessTokenSecret);
var user = service.VerifyCredentials();
var result = service.SendDirectMessage(recipient, message);
回答2:
Have you checked that you are following the message recipient and that they are following you? This must be the case before you can DM a person.
来源:https://stackoverflow.com/questions/8841638/send-direct-messages-using-twitter-api