202312 - Twitter API v2
This commit is contained in:
BIN
Binary file not shown.
|
After Width: | Height: | Size: 357 KiB |
@@ -1,88 +1,14 @@
|
||||
<?php
|
||||
|
||||
use Abraham\TwitterOAuth\TwitterOAuth;
|
||||
|
||||
// Twitter OAuth Settings:
|
||||
/* TOPISTO
|
||||
define('CONSUMER_KEY', 'HBInbm93bM80z86XVJ34rtjxO');
|
||||
define('CONSUMER_SECRET', 'zpdSp8yv9R2VODgPRA0RZbiO7VE8vSPNLVNg9zI0HjWnJKADO8');
|
||||
define('ACCESS_TOKEN', '315679287-EjINhav5VbJPscb4h9pw3WwveeeX0ShpnIjcawDe');
|
||||
define('ACCESS_TOKEN_SECRET', 'SIFKfPYEoIdlAyeQKVS3y067uNFuLpy013wRycJ8VxNcd');
|
||||
*/
|
||||
|
||||
/* R. Topisto */
|
||||
define('CONSUMER_KEY', '9Ie6CjwM5eZSQu5Xnbel4PBqm');
|
||||
define('CONSUMER_SECRET', 'pI4ha5gW7Lft6Lg5xP7nH49Yqbm8PwLn1EP8D1qKg1q0SYd5t2');
|
||||
define('ACCESS_TOKEN', '840479603143630849-c3xFLJFvo77ubP1njoXHpFu9LQqKLR8');
|
||||
define('ACCESS_TOKEN_SECRET', 'EW4Zi10cQnNfoOunnEF1svJ3omz223U57G6KuYo5ZZ2Ls');
|
||||
|
||||
define('TWITTER_WIDTH', 880);
|
||||
define('TWITTER_HEIGHT', 440);
|
||||
|
||||
class twitter
|
||||
{
|
||||
public static function tweet($message, $media='')
|
||||
{
|
||||
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
|
||||
$content = $twitter->get('account/verify_credentials');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$parameters = array("status" => $message);
|
||||
|
||||
if (($media != NULL)&&($media != ''))
|
||||
{
|
||||
$imageMedia = $twitter->upload('media/upload', array('media' => $media));
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$parameters = array(
|
||||
"status" => $message,
|
||||
"media_ids" => $imageMedia->media_id_string);
|
||||
}
|
||||
|
||||
$statuses = $twitter->post("statuses/update", $parameters);
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public static function thanksRetweet()
|
||||
{
|
||||
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
|
||||
$content = $twitter->get('account/verify_credentials');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$results = $twitter->get('statuses/retweets_of_me');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
/* TO DO */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public static function thanksFollowers()
|
||||
{
|
||||
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
|
||||
$content = $twitter->get('account/verify_credentials');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$results = $twitter->get('followers/list');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$followers = json_decode(file_get_contents('followers.json'));
|
||||
foreach($results->users as $user)
|
||||
if (!in_array($user->screen_name, $followers))
|
||||
{
|
||||
$parameters = array("status" => '@'.$user->screen_name.' thanks following me !');
|
||||
$followers[] = $user->screen_name;
|
||||
$statuses = $twitter->post("statuses/update", $parameters);
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
break; // Un à la fois ...
|
||||
}
|
||||
file_put_contents('followers.json', json_encode($followers));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
// Client ID
|
||||
// TE5jWFRIVTZVQkdnT2FIeEJyYTY6MTpjaQ
|
||||
// Client Secret
|
||||
// GyZkEE69j0UPPKfmal9tT287-ZVw7vQbV20qvDPTFLCgNOplUk
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
use Abraham\TwitterOAuth\TwitterOAuth;
|
||||
|
||||
// Twitter OAuth Settings:
|
||||
/* TOPISTO
|
||||
define('CONSUMER_KEY', 'HBInbm93bM80z86XVJ34rtjxO');
|
||||
define('CONSUMER_SECRET', 'zpdSp8yv9R2VODgPRA0RZbiO7VE8vSPNLVNg9zI0HjWnJKADO8');
|
||||
define('ACCESS_TOKEN', '315679287-EjINhav5VbJPscb4h9pw3WwveeeX0ShpnIjcawDe');
|
||||
define('ACCESS_TOKEN_SECRET', 'SIFKfPYEoIdlAyeQKVS3y067uNFuLpy013wRycJ8VxNcd');
|
||||
*/
|
||||
|
||||
/* R. Topisto */
|
||||
define('CONSUMER_KEY', '9Ie6CjwM5eZSQu5Xnbel4PBqm');
|
||||
define('CONSUMER_SECRET', 'pI4ha5gW7Lft6Lg5xP7nH49Yqbm8PwLn1EP8D1qKg1q0SYd5t2');
|
||||
define('ACCESS_TOKEN', '840479603143630849-c3xFLJFvo77ubP1njoXHpFu9LQqKLR8');
|
||||
define('ACCESS_TOKEN_SECRET', 'EW4Zi10cQnNfoOunnEF1svJ3omz223U57G6KuYo5ZZ2Ls');
|
||||
|
||||
define('TWITTER_WIDTH', 880);
|
||||
define('TWITTER_HEIGHT', 440);
|
||||
|
||||
class twitter
|
||||
{
|
||||
public static function tweet($message, $media='')
|
||||
{
|
||||
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
|
||||
$content = $twitter->get('account/verify_credentials');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$parameters = array("status" => $message);
|
||||
|
||||
if (($media != NULL)&&($media != ''))
|
||||
{
|
||||
$imageMedia = $twitter->upload('media/upload', array('media' => $media));
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$parameters = array(
|
||||
"status" => $message,
|
||||
"media_ids" => $imageMedia->media_id_string);
|
||||
}
|
||||
|
||||
$statuses = $twitter->post("statuses/update", $parameters);
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public static function thanksRetweet()
|
||||
{
|
||||
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
|
||||
$content = $twitter->get('account/verify_credentials');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$results = $twitter->get('statuses/retweets_of_me');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
/* TO DO */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public static function thanksFollowers()
|
||||
{
|
||||
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
|
||||
$content = $twitter->get('account/verify_credentials');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$results = $twitter->get('followers/list');
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
|
||||
$followers = json_decode(file_get_contents('followers.json'));
|
||||
foreach($results->users as $user)
|
||||
if (!in_array($user->screen_name, $followers))
|
||||
{
|
||||
$parameters = array("status" => '@'.$user->screen_name.' thanks following me !');
|
||||
$followers[] = $user->screen_name;
|
||||
$statuses = $twitter->post("statuses/update", $parameters);
|
||||
if ($twitter->getLastHttpCode() !== 200) return FALSE;
|
||||
break; // Un à la fois ...
|
||||
}
|
||||
file_put_contents('followers.json', json_encode($followers));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/* R. Topisto */
|
||||
define('CONSUMER_KEY', '9Ie6CjwM5eZSQu5Xnbel4PBqm');
|
||||
define('CONSUMER_SECRET', 'pI4ha5gW7Lft6Lg5xP7nH49Yqbm8PwLn1EP8D1qKg1q0SYd5t2');
|
||||
define('ACCESS_TOKEN', '840479603143630849-c3xFLJFvo77ubP1njoXHpFu9LQqKLR8');
|
||||
define('ACCESS_TOKEN_SECRET', 'EW4Zi10cQnNfoOunnEF1svJ3omz223U57G6KuYo5ZZ2Ls');
|
||||
|
||||
// Client ID
|
||||
// TE5jWFRIVTZVQkdnT2FIeEJyYTY6MTpjaQ
|
||||
// Client Secret
|
||||
// GyZkEE69j0UPPKfmal9tT287-ZVw7vQbV20qvDPTFLCgNOplUk
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
require 'twitter.php';
|
||||
require '../../generique/inc/twitter.php';
|
||||
|
||||
twitter::tweet('TOPISTO test API V2');
|
||||
|
||||
?>
|
||||
@@ -21,6 +21,8 @@ require TOPISTO_PATH.'/ressources/vendor/autoload.php';
|
||||
// ---
|
||||
require_once APP_PATH.'/blockchain/inc/block.php';
|
||||
require 'inc/twitter.php';
|
||||
require '../generique/inc/twitter.php';
|
||||
require '../config.php';
|
||||
|
||||
$methode='spline';
|
||||
if (isset($argv[3])) $methode=$argv[3];
|
||||
@@ -32,30 +34,35 @@ if ($the_block === FALSE) die();
|
||||
// ---
|
||||
// --- Remercier les followers
|
||||
// ---
|
||||
twitter::thanksFollowers();
|
||||
// twitter::thanksFollowers();
|
||||
|
||||
$image_file=DATA_PATH."/$methode/".$argv[1].'.png';
|
||||
|
||||
if (file_exists($image_file))
|
||||
{
|
||||
$image_origine = imagecreatefrompng($image_file);
|
||||
$image_twitter = imagecreatetruecolor(TWITTER_WIDTH, TWITTER_HEIGHT);
|
||||
|
||||
$fond = imagecolorallocate($image_twitter, 255, 255, 255);
|
||||
//imagecolortransparent($image_twitter, $fond);
|
||||
imagefilledrectangle($image_twitter, 0, 0, TWITTER_WIDTH, TWITTER_HEIGHT, $fond);
|
||||
if (image_origine) {
|
||||
$image_twitter = imagecreatetruecolor(TWITTER_WIDTH, TWITTER_HEIGHT);
|
||||
if ($image_twitter) {
|
||||
|
||||
$ratio = TWITTER_HEIGHT / imagesy($image_origine);
|
||||
$new_width = $ratio * imagesx($image_origine);
|
||||
$fond = imagecolorallocate($image_twitter, 0, 0, 0);
|
||||
imagefilledrectangle($image_twitter, 0, 0, TWITTER_WIDTH, TWITTER_HEIGHT, $fond);
|
||||
|
||||
$xpos = floor((TWITTER_WIDTH - $new_width) / 2);
|
||||
$ypos = 0;
|
||||
$ratio = TWITTER_HEIGHT / imagesy($image_origine);
|
||||
$new_width = $ratio * imagesx($image_origine);
|
||||
|
||||
imagecopyresized($image_twitter, $image_origine, $xpos, $ypos, 0, 0, $new_width, TWITTER_HEIGHT, imagesx($image_origine), imagesy($image_origine));
|
||||
$xpos = floor((TWITTER_WIDTH - $new_width) / 2);
|
||||
$ypos = 0;
|
||||
|
||||
$image_file = DATA_PATH."/twitterbot/".$argv[1].'.png';
|
||||
imagecopyresized($image_twitter, $image_origine, $xpos, $ypos, 0, 0, $new_width, TWITTER_HEIGHT, imagesx($image_origine), imagesy($image_origine));
|
||||
|
||||
imagepng($image_twitter,$image_file);
|
||||
$image_file = DATA_PATH."/twitterbot/".$argv[1].'.png';
|
||||
|
||||
if (!imagepng($image_twitter,$image_file)) $image_file='';
|
||||
|
||||
} else echo("Pbme avec image TWITTER ".PHP_EOL);
|
||||
} else echo("Pbme avec $image_file ".PHP_EOL);
|
||||
|
||||
// ---
|
||||
// --- Un petit peu de stéganographie ...
|
||||
@@ -69,9 +76,9 @@ if (file_exists($image_file))
|
||||
// ---
|
||||
// --- Tweet
|
||||
// ---
|
||||
$tweet = "#computerart #creativecoding #generativeart :".PHP_EOL."#bitcoin #blockchain 's".PHP_EOL;
|
||||
$tweet .= $argv[2]." Block, Height : ".$the_block->height.PHP_EOL;
|
||||
$tweet .= "[ See more on www.topisto.net ]";
|
||||
$tweet = "#computerart #creativecoding #generativeart :\\n#bitcoin #blockchain \\n";
|
||||
$tweet .= $argv[2]." Block, Height : ".$the_block->height;
|
||||
$tweet .= "\\n[ See more on www.topisto.net ]";
|
||||
$success = twitter::tweet($tweet, $image_file);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,10 +47,12 @@ fi
|
||||
|
||||
if [ -f $DATA_PATH/hasard/$BLOCK_HASH.png ]
|
||||
then
|
||||
echo Suppression $DATA_PATH/twitterbot/$BLOCK_HASH
|
||||
rm $DATA_PATH/twitterbot/$BLOCK_HASH
|
||||
if [ ! -f $DATA_PATH/twitterbot/$BLOCK_HASH ]
|
||||
then
|
||||
echo Tweet for $BLOCK_HASH $BLOCK_NAME
|
||||
php robot.php $BLOCK_HASH $BLOCK_NAME hasard $BLOCK_HEIGHT
|
||||
echo php robot.php $BLOCK_HASH $BLOCK_NAME hasard $BLOCK_HEIGHT
|
||||
|
||||
#
|
||||
# On met un marqueur pour ne pas retweeter
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
// ---
|
||||
// --- Listening to blockchain.info to get the last block
|
||||
// --- Drawing the block as a Treemap
|
||||
// --- Tweet it
|
||||
// ---
|
||||
|
||||
// ---
|
||||
// --- La config globale
|
||||
// ---
|
||||
require_once '../../global/inc/config.php';
|
||||
|
||||
// ---
|
||||
// --- External dependances
|
||||
// ---
|
||||
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
|
||||
|
||||
// ---
|
||||
// --- Internal dependances
|
||||
// ---
|
||||
require_once APP_PATH.'/blockchain/inc/block.php';
|
||||
require 'inc/twitter.php';
|
||||
|
||||
$methode='spline';
|
||||
if (isset($argv[3])) $methode=$argv[3];
|
||||
|
||||
$block_hash = $argv[1];
|
||||
$the_block = blockchain::getBlockWithHash($block_hash);
|
||||
if ($the_block === FALSE) die();
|
||||
|
||||
// ---
|
||||
// --- Remercier les followers
|
||||
// ---
|
||||
// twitter::thanksFollowers();
|
||||
|
||||
$image_file=DATA_PATH."/$methode/".$argv[1].'.png';
|
||||
|
||||
if (file_exists($image_file))
|
||||
{
|
||||
$image_origine = imagecreatefrompng($image_file);
|
||||
$image_twitter = imagecreatetruecolor(TWITTER_WIDTH, TWITTER_HEIGHT);
|
||||
|
||||
$fond = imagecolorallocate($image_twitter, 255, 255, 255);
|
||||
//imagecolortransparent($image_twitter, $fond);
|
||||
imagefilledrectangle($image_twitter, 0, 0, TWITTER_WIDTH, TWITTER_HEIGHT, $fond);
|
||||
|
||||
$ratio = TWITTER_HEIGHT / imagesy($image_origine);
|
||||
$new_width = $ratio * imagesx($image_origine);
|
||||
|
||||
$xpos = floor((TWITTER_WIDTH - $new_width) / 2);
|
||||
$ypos = 0;
|
||||
|
||||
imagecopyresized($image_twitter, $image_origine, $xpos, $ypos, 0, 0, $new_width, TWITTER_HEIGHT, imagesx($image_origine), imagesy($image_origine));
|
||||
|
||||
$image_file = DATA_PATH."/twitterbot/".$argv[1].'.png';
|
||||
|
||||
imagepng($image_twitter,$image_file);
|
||||
|
||||
// ---
|
||||
// --- Un petit peu de stéganographie ...
|
||||
// ---
|
||||
/* Ca fait des fichiers trop gros !
|
||||
$processor = new KzykHys\Steganography\Processor();
|
||||
$image = $processor->encode($image_file, 'TOPISTO is making art with block '.$the_block->height);
|
||||
$image->write($image_file);
|
||||
*/
|
||||
|
||||
// ---
|
||||
// --- Tweet
|
||||
// ---
|
||||
$tweet = "#computerart #creativecoding #generativeart :".PHP_EOL."#bitcoin #blockchain 's".PHP_EOL;
|
||||
$tweet .= $argv[2]." Block, Height : ".$the_block->height.PHP_EOL;
|
||||
$tweet .= "[ See more on www.topisto.net ]";
|
||||
$success = twitter::tweet($tweet, $image_file);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user