我正在尝试通过API直接向我自己和另一名工作人员发送内部服务器通知.我已经浏览了dev.twitter上的API设置,并且我已经下载了abraham的twitteroauth库.
我需要在哪里直接从服务器(通过我的帐户)发送消息,而无需每次使用浏览器登录?上次我使用twitter API是在oauth之前,所以很长一段时间过去了.
tl; dr需要通过Twitter发送直接消息而不会看到此消息
max*_*dec 16
您可以从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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9975 次 |
| 最近记录: |