使用cURL远程进行Twitter直接消息传递

Twitter DM

Twitter's direct messaging functionality is great. While simple tweeting communicates "just a clever quip," direct messaging communicates "listen here b*tch, this is important enough that you need to get this message NOW via text message." Twitter's API allows you direct message remotely so now you can let your website DM you (and call you a b*tch) any time you want!

Twitter的直接消息传递功能很棒。 简单的推文交流“只是一个聪明的傻瓜”,而直接消息传递则交流“在这里听,这很重要,以至于您需要立即通过文本消息获得此消息”。 Twitter的API允许您远程定向消息,因此,现在您可以随时让您的网站DM您(并称您为ab * tch)!

Shell cURL命令 (The Shell cURL Command)


curl -u davidwalshblog:myPass -d "text=Testing a remote direct message via C
URL&user=fellowTweeter" http://twitter.com/direct_messages/new.xml


This example shows the cURL command as you'd type it in the terminal.

此示例显示了在终端中键入cURL命令的过程。

PHP用法 (PHP Usage)


$result = shell_exec('curl -u davidwalshblog:myPass -d "text=Testing a remote direct message via C
URL&user=fellowTweeter" http://twitter.com/direct_messages/new.xml');

This is how you could use the command in PHP.

样本XML响应 (Sample XML Response)


<!-- Successful! -->
<?xml version="1.0" encoding="UTF-8"?>
<direct_message>
  <id>186275699</id>
  <sender_id>15759583</sender_id>
  <text>Testing a direct message.</text>
  <recipient_id>15759583</recipient_id>
  <created_at>Sat Jun 20 00:13:41 +0000 2009</created_at>
  <sender_screen_name>davidwalshblog</sender_screen_name>
  <recipient_screen_name>davidwalshblog</recipient_screen_name>
  <sender>
    <id>15759583</id>
    <name>davidwalshblog</name>
    <screen_name>davidwalshblog</screen_name>
    <location>Madison, WI, US</location>
    <description>Flexile Programmer, MooTools Core Team Member, JavaScript Fanatic, CSS Tinkerer, PHP Hacker, and web lover.</description>
    <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/57860553/footer-logo_normal.jpg</profile_image_url>
    <url>https://davidwalsh.name</url>
    <protected>false</protected>
    <followers_count>1834</followers_count>
    <profile_background_color>EEEEEE</profile_background_color>
    <profile_text_color>000000</profile_text_color>
    <profile_link_color>2A447B</profile_link_color>
    <profile_sidebar_fill_color>CDCDCD</profile_sidebar_fill_color>
    <profile_sidebar_border_color>999999</profile_sidebar_border_color>
    <friends_count>20</friends_count>
    <created_at>Thu Aug 07 04:18:53 +0000 2008</created_at>
    <favourites_count>3</favourites_count>
    <utc_offset>-21600</utc_offset>
    <time_zone>Central Time (US & Canada)</time_zone>
    <profile_background_image_url>http://s3.amazonaws.com/twitter_production/profile_background_images/15318223/twitter-background.png</profile_background_image_url>
    <profile_background_tile>false</profile_background_tile>
    <statuses_count>1734</statuses_count>
    <notifications>false</notifications>
    <verified>false</verified>
    <following>false</following>
  </sender>
  <recipient>
    <id>15759583</id>
    <name>davidwalshblog</name>
    <screen_name>davidwalshblog</screen_name>
    <location>Madison, WI, US</location>
    <description>Flexile Programmer, MooTools Core Team Member, JavaScript Fanatic, CSS Tinkerer, PHP Hacker, and web lover.</description>
    <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/57860553/footer-logo_normal.jpg</profile_image_url>
    <url>https://davidwalsh.name</url>
    <protected>false</protected>
    <followers_count>1834</followers_count>
    <profile_background_color>EEEEEE</profile_background_color>
    <profile_text_color>000000</profile_text_color>
    <profile_link_color>2A447B</profile_link_color>
    <profile_sidebar_fill_color>CDCDCD</profile_sidebar_fill_color>
    <profile_sidebar_border_color>999999</profile_sidebar_border_color>
    <friends_count>20</friends_count>
    <created_at>Thu Aug 07 04:18:53 +0000 2008</created_at>
    <favourites_count>3</favourites_count>
    <utc_offset>-21600</utc_offset>
    <time_zone>Central Time (US & Canada)</time_zone>
    <profile_background_image_url>http://s3.amazonaws.com/twitter_production/profile_background_images/15318223/twitter-background.png</profile_background_image_url>
    <profile_background_tile>false</profile_background_tile>
    <statuses_count>1734</statuses_count>
    <notifications>false</notifications>
    <verified>false</verified>
    <following>false</following>
  </recipient>
</direct_message>



<!-- ERROR RESPONSE -->
<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <request>/direct_messages/new.xml</request>
  <error>You cannot send messages to users who are not following you.</error>
</hash>


Loads of information if your DM is successful -- a simple error response if your attempt fails.

如果您的DM成功,则会加载大量信息-如果尝试失败,则是简单的错误响应。

So why automate a DM? I think one handy time to implement direct message automation is when you want to receive text messages when events occur on the website. Say you're a salesperson and you have a "request a phone call" form on your site. Since you're out of the office much of the day (driving), you don't have the means to check your email. Instead of setting up a text messaging / SMS system, simply set up a Twitter account and take advantage of Twitter's texting capabilities.

那么,为什么要自动化DM? 我认为实现直接消息自动化的一个方便时间是当您希望在网站上发生事件时接收文本消息时。 假设您是销售人员,并且在您的网站上有一个“请求电话”表格。 由于您一天中大部分时间不在办公室(开车),因此您无法检查电子邮件。 无需设置短信/ SMS系统,只需设置一个Twitter帐户并利用Twitter的短信功能即可。

Would you ever want automated tweets or direct messages from your website?

您是否要从网站上自动发送推文或直接发送消息?

翻译自: https://davidwalsh.name/twitter-dm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值