如何通过 OAuth (Twitter) 从应用程序的 screen_name 发送直接消息

发布于 2024-10-05 12:13:10 字数 608 浏览 0 评论 0原文

我对这个看似简单的概念有点困惑。基本上,我正在构建一个网络应用程序,如果用户的帐户发生事件,该应用程序将通过 Twitter 直接消息通知用户。我用 PHP 构建它,并使用 CakePHP 作为底层框架。我希望能够通过 oAuth “从”应用程序发送直接消息。我使用 Twurl 控制台(位于 http://dev.twitter.com/console)发送 POST请求通过

http://api.twitter.com/1/direct_messages/new.xml?screen_name=<my screenname>&text=<content of dm>

当我检查我的 DM 时,我基本上会收到我自己的 DM。这是因为 Twurl 控制台在从应用程序发送内容时使用您的屏幕名,或者因为在调用 direct_message/new.xml 时,您正在从您的帐户发送 DM,该帐户已通过 Twurl 中的测试应用程序进行身份验证。最后,我希望完成与 spontwts 相同的事情 - 当您的帐户发生问题时通过 DM 通知您。非常感谢任何输入、资源、链接或代码示例:)

I'm getting a little confused on this seemingly simple concept. Basically I'm building a web app that will notify users via a Twitter Direct Message if an event occurred on their account with me. I'm building it in PHP with CakePHP as the underlying framework. I'd like to be able to send the direct message "from" the application via oAuth. I used the Twurl Console (at http://dev.twitter.com/console) to send a POST request via

http://api.twitter.com/1/direct_messages/new.xml?screen_name=<my screenname>&text=<content of dm>

When I check my DM's I basically get a DM from myself. Is that because the Twurl console uses your screenname when sending stuff from applications or because when calling the direct_message/new.xml you are sending a DM from your account which was authenticated with the test application in Twurl. In the end I'm looking to accomplish the same thing that spontwts does - notify you via DM when something happens on your account. Any input, resources, links, or code samples are very much appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝情姑娘 2024-10-12 12:13:10

您可以通过关注者的屏幕名称发送直接消息
其中 userID 是该人的屏幕名称,

ConfigurationBuilder cb=new ConfigurationBuilder();

cb.setOAuthAccessToken("Your App Access Token");

cb.setOAuthAccessTokenSecret("Your App Token Secret");

cb.setOAuthConsumerKey("Your App ConsumerKey");

cb.setOAuthConsumerSecret("Your App ConsumerSecret");

cb.setIncludeRTsEnabled(true);


TwitterFactory tf=new TwitterFactory(cb.build());


Twitter twitter=tf.getInstance();

twitter.sendDirectMessage(userID, "Message");

并在应用程序中提供读/写/私信权限。

You can send the direct message via screen name of your followers by
Where userID is the screen name of the person,

ConfigurationBuilder cb=new ConfigurationBuilder();

cb.setOAuthAccessToken("Your App Access Token");

cb.setOAuthAccessTokenSecret("Your App Token Secret");

cb.setOAuthConsumerKey("Your App ConsumerKey");

cb.setOAuthConsumerSecret("Your App ConsumerSecret");

cb.setIncludeRTsEnabled(true);


TwitterFactory tf=new TwitterFactory(cb.build());


Twitter twitter=tf.getInstance();

twitter.sendDirectMessage(userID, "Message");

And Provide the Read/Write/Direct Message Permission in the app.

故事未完 2024-10-12 12:13:10

首先,如果你想让你的应用程序与 Twitter 交互,你必须先注册它。 Twitter 文档 准确地解释了这是如何完成的。

获得此信息后,请按照 OAuth 版本 1 授权协议获取访问令牌。通过拥有访问令牌,您基本上可以调用 Twitter 受保护的资源。完整的协议(在上面的链接中给出)向您展示了如何实现这一目标。由于您已经通过 Twitter(OAuth 称为服务提供商)进行了身份验证,因此控制台可以轻松绕过 OAuth 协议。 OAuth 仅允许服务提供商进行客户端凭据身份验证。

我希望这有帮助。

First of all, if you want your application to interface with Twitter, you have to register it first. The Twitter Document explains exactly how this is done.

Once you have this, follow the OAuth version 1 Authorization protocol in getting an Access Token. By having an access token, you can essentially call Twitter protected resources. The full protocol (given on link above) shows you how to achieve this. The console can easily bypass the OAuth protocol since you've authenticated through Twitter (which OAuth calls, the service provider). OAuth allows only the service provider to do client credential authentication.

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文