Skip to content

Instantly share code, notes, and snippets.

@gioxx
Created January 5, 2019 11:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gioxx/5149ce4058308f85e440c14870873c5b to your computer and use it in GitHub Desktop.
Save gioxx/5149ce4058308f85e440c14870873c5b to your computer and use it in GitHub Desktop.
Uno script PHP che ti permette di pubblicare un tweet contenente un countdown di giorni generato tramite timercheck.io, maggiori informazioni su https://wp.me/pdQ5q-9YA
<?php
require_once "autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
// API @TUOACCOUNTTWITTER
define('CONSUMER_KEY', 'XXX');
define('CONSUMER_SECRET', 'XXX');
define('ACCESS_TOKEN', 'XXX');
define('ACCESS_TOKEN_SECRET', 'XXX');
$json = file_get_contents('https://timercheck.io/Test-Gioxx.org/60');
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// Credits for json decode: https://stackoverflow.com/questions/15617512/get-json-object-from-url
$obj = json_decode($json);
if ($obj->status == "ok") {
$secondi = $obj->seconds_remaining;
$giorni = $secondi / 86400;
$status = 'Countdown ⏰: -'.round($giorni).'. Buongiorno! ☕'; //text for your tweet.
$post_tweets = $connection->post("statuses/update", ["status" => $status]);
} else {
$status = 'Buongiorno! ☕'; //text for your tweet.
$post_tweets = $connection->post("statuses/update", ["status" => $status]);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment