Send Direct Messages using twitter API

走远了吗. 提交于 2019-12-25 02:15:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!