Reputation: 4765
I'm trying to send internal server notices via direct message to myself and another staff member through the API. I've gone through the API setup on dev.twitter and I've downloaded abraham's twitteroauth library.
Where do I need to be looking to send a message direct from the server (Through my account) without having to log in everytime with a browser? Last time I used the twitter API was before oauth, so quite some time has passed.
tl;dr Need to send direct messages through twitter without seeing this
Upvotes: 6
Views: 10403
Reputation: 5725
You can get your personal tokens from you app page on dev.twitter.com and use it without having to Sign in with Twitter
.
On your app page under the section OAuth settings
get:
And under Your access token
get:
Check that the access level is Read, write, and direct messages
. Otherwise change it in the Settings
tab and recreate your access tokens (there is a button on the bottom of the Details
tab).
Then in 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);
Upvotes: 16