【问题标题】:Sending direct messages from twitter API从 twitter API 发送直接消息
【发布时间】:2012-12-21 00:29:58
【问题描述】:

我正在尝试通过 API 通过直接消息向我自己和另一位员工发送内部服务器通知。我已经完成了 dev.twitter 上的 API 设置,并下载了 abraham's twitteroauth 库。

我需要在哪里寻找直接从服务器发送消息(通过我的帐户),而不必每次都使用浏览器登录?我上次使用 twitter API 是在 oauth 之前,所以已经过去了一段时间。

tl;dr 需要通过 twitter 发送直接消息而不看到这个

【问题讨论】:

  • 您可以从dev.twitter.com 的应用页面获取您的个人令牌并使用它而无需Sign in with Twitter

标签: php twitter


【解决方案1】:

您可以从dev.twitter.com 上的应用页面获取您的个人令牌并使用它而无需Sign in with Twitter

OAuth settings 部分下的应用页面上获取:

  • 消费者密钥
  • 消费者的秘密

Your access token 下得到:

  • 访问令牌
  • 访问令牌密码

检查访问级别是否为Read, write, and direct messages。否则,请在 Settings 选项卡中更改它并重新创建您的访问令牌(Details 选项卡底部有一个按钮)。

然后在php中

require('Abrahams library');

// Get everything you need from the dev.twitter.com/apps page
$consumer_key = 'APP KEY';
$consumer_secret = 'APP SECRET';
$oauth_token = 'YOUR TOKEN';
$oauth_token_secret = 'YOUR TOKEN SECRET';

// Initialize the connection
$connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);

// Send a direct message
$options = array("screen_name" => "theGuyIWantToDM", "text" => "Hey that's my message");
$connection->post('direct_messages/new', $options);

【讨论】:

    猜你喜欢
    • 2012-02-09
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2011-05-08
    相关资源
    最近更新 更多