使用 Twitter API 发送私信 [英] Send Direct Messages using twitter API
问题描述
我尝试使用 twitter API 使用 C# 发送直接消息,但 Twitter 一直说:
I trying to use twitter API to send direct messages using C# but Twitter keeps saying:
远程服务器返回错误:(401) 未经授权."
"The remote server returned an error: (401) Unauthorized."
但这没有意义,因为我可以在我获得授权的地方使用其他 API 调用.
But this has no sense because I could use other API calls where I was authorized.
一些背景信息:
我创建了一个具有以下访问权限的应用程序:读取、写入和访问直接消息
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/发布/状态/更新
我还可以检索发送给我的所有直接消息:
I could also retrieve all the direct messages sent to me:
https://dev.twitter.com/docs/api/1/获取/直接消息
问题是当我尝试发送直接消息时:
The problem is when I try to send a direct message:
https://dev.twitter.com/docs/api/1/post/direct_messages/new
推荐答案
我还不知道出了什么问题,但我可以使用一个名为 tweetsharp 的开源项目使其工作.您可以下载它并查看有效的代码:
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:
这是一个代码示例
var service = new TwitterService(consumerKey, consumerSecret, accessToken, accessTokenSecret);
var user = service.VerifyCredentials();
var result = service.SendDirectMessage(recipient, message);
这篇关于使用 Twitter API 发送私信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!