Viewing file: twitter_auto.php (2.86 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
require('twitteroauth.php'); //incluir la librería
define('_CONSUMER_KEY','rGYinkAD5NCT2BmNOSNSUA'); //La obtenes en el paso 1
define('_CONSUMER_SECRET','DWE3JowJ5pOemhOklTPgFp6n0CugBqpo04CEiIcXQs'); //La obtenes en el paso 1
define('_OAUTH_TOKEN','113912607-Om4GBuqkylrHlgnUVEaEH3349xX0bvkTByeIxeSD'); //La obtenes en el paso 1
define('_OAUTH_TOKEN_SECRET','bntu6wCQSfDiYPzJ97F551Y10rQgQhrBHJYPVzJ2ao'); //La obtenes en el paso 1
include "/home/wwwroot/frames/conn.php";
// metemos los subidos en el dia de ayer.
$fecha=date('Y-m-d', strtotime('-1 days'));
$cript = new Encriptor();
$sql="SELECT *
FROM `libros`
WHERE fecha_subida > '$fecha 00:00:00'
AND fecha_subida < '$fecha 23:59:59'
and inftp=1";
$ccadena="";
$res=mysql_query($sql,$conn);
while ($row=mysql_fetch_array($res)){
$ccadena.="||".$row[id];
}
echo $ccadena= substr($ccadena,2);
$q1=$cript->encrypt($ccadena);
$q2= $cript->encrypt("Lista de libros subidos con fecha $fecha");
// y aqui generamos el enlace con 9fx.us
$enlace_bruto=utf8_encode("http://www.papyrefb2.net/frames/listatwitter.php?q1=$q1@@**@@$q2");
$handle=fopen("http://9fx.us/index.php?url=$enlace_bruto&format=txt",'r');
while (!feof($handle)) {
$ultimos= fgets($handle);
}
echo "<br>ultimos:".$ultimos."<br>";
$user="papyrefb2";
$pass="ilvm2rg2";
$mensaje="$ultimos Lista de libros subidos ayer a papyrefb2.net #ebooks";
//***************************************************
// $bit=tinyurl($link); //reducimos el link con la api de bit.ly
// $quedan=(140-strlen($bit))-4; // calculo los caracteres restantes que me quedan para publicar restando los puntos suspensivo
// $mensaje=substr($mensaje,0,$quedan).' ...'.$bit; // corto el mensaje en caso de que sea muy largo
//Realizamos la conexión
$connection = getConnectionWithAccessToken();
//Publicamos el mensaje en twitter
$twitter=$connection->post('statuses/update', array('status' =>utf8_encode($mensaje)));
print_r($twitter);
// metemos los más descargados ayer
//declaramos la función que realiza la conexión a tu aplicación de twitter
function getConnectionWithAccessToken() {
$connection = new TwitterOAuth(_CONSUMER_KEY, _CONSUMER_SECRET,_OAUTH_TOKEN, _OAUTH_TOKEN_SECRET);
return $connection;
}
//Función para acortar URL con bit.ly . Primero debemos registrarnos en http://bit.ly para obtener clave api y usuario
function tinyurl($url_larga){
$tiny = "http://9fx.us/index.php?url=$url_larga&format=txt";
$sesion = curl_init();
curl_setopt ( $sesion, CURLOPT_URL, $tiny );
curl_setopt ( $sesion, CURLOPT_RETURNTRANSFER, 1 );
$url_tiny = curl_exec ( $sesion );
curl_close( $sesion );
return($url_tiny);
}
|