I have create a media type to sent notification as DM on Twitter.
Before you can use this script you have to create a twitter app and get the secret and acccess key from the account where you want to sent messages from.
In the profile of the user you set the twitter-account you want to sent a message to.
The sender has to follow that twitter account and that twitter account needs to follow you.
It uses the default twitteroauth files that you can download from twitter.
You have to download it and put it a folder called twitteroauth in the same directory as this script.
Before you can use this script you have to create a twitter app and get the secret and acccess key from the account where you want to sent messages from.
In the profile of the user you set the twitter-account you want to sent a message to.
The sender has to follow that twitter account and that twitter account needs to follow you.
It uses the default twitteroauth files that you can download from twitter.
You have to download it and put it a folder called twitteroauth in the same directory as this script.
Code:
#!/usr/bin/php
<?php
/* Load required lib files. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('twitteroauth/config.php');
//acceskey and secret.
$access = "<your access>";
$secret = "<your secret>";
if (count($argv)<3) {
die ("Usage: ".$argv[0]." recipient \"subject\" \"message\"\n");
}
if ( $debug )
file_put_contents($logfilelocation."twitter_alert_".date("YmdHis"), serialize($argv));
$to = $argv[1];
$subject = $argv[2]; // not being used
$message = $argv[3];
/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access, $secret);
/* If method is set change API call made. Test is called by default. */
$content = $connection->get('account/verify_credentials');
/* Some example calls */
$tw = $connection->post('direct_messages/new', array( 'screen_name' => $to, 'text' => $subject ) );
/* Include HTML to display on the page */
include('twitteroauth/html.inc');
Comment