forked from qwerty/tupali
66 lines
2.5 KiB
PHP
Executable File
66 lines
2.5 KiB
PHP
Executable File
<?php
|
|
session_start();
|
|
ini_set('display_errors', 1);
|
|
|
|
require 'autoload.php';
|
|
use Abraham\TwitterOAuth\TwitterOAuth;
|
|
require_once('config.php');
|
|
|
|
/* Crear un objeto TwitteroAuth con las credenciales de la aplicacion y el token temporal */
|
|
//$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
|
|
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
|
|
$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
|
|
|
|
/* Solicitar a twitter el token de acceso */
|
|
//$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
|
|
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
|
|
|
|
|
|
/* Guardar el token de acceso. Normalmente, este token se guardará también en una base
|
|
de datos para volver a ser utilizado en otras ocasiones. */
|
|
$_SESSION['access_token'] = $access_token;
|
|
|
|
/* Eliminar el token temporal de solicitud */
|
|
unset($_SESSION['oauth_token']);
|
|
unset($_SESSION['oauth_token_secret']);
|
|
|
|
/* Si todo va bien, presentar al usuario la página principal "index.php" del servicio */
|
|
//if (200 == $connection->http_code) {
|
|
/* El usuario ha sido verificado */
|
|
$_SESSION['status'] = 'verified';
|
|
echo send_tweet($access_token);
|
|
//}
|
|
function base64_encode_image ($filename=string,$filetype=string) {
|
|
if ($filename) {
|
|
$imgbinary = fread(fopen($filename, "r"), filesize($filename));
|
|
return base64_encode($imgbinary);
|
|
}
|
|
}
|
|
|
|
function send_tweet($access_token) {
|
|
$tweet = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
|
|
$access_token['oauth_token'], $access_token['oauth_token_secret']);
|
|
$nombre= $_SESSION['logis'].".png";
|
|
$nombre = "$_SESSION[path_images_secure]/600/$nombre";
|
|
|
|
$media1 = $tweet->upload('media/upload', array('media' => "$nombre"));
|
|
$parameters = array('status' =>"$_SESSION[mensaje] #BrigadaDigital #CD2015 http://datos.labmde.org/jlogis",'media_ids' => implode(',', array($media1->media_id_string)),
|
|
);
|
|
|
|
$result = $tweet-> post('statuses/update', $parameters);
|
|
$image = "$nombre";
|
|
$base64 = base64_encode_image (''.$image,'png');
|
|
$result = $tweet-> post('account/update_profile_image', array('image' => $base64.';type=image/jpg;filename='.$image));
|
|
|
|
// $message = "Bonito dia $nombre";
|
|
// $tweet->post('statuses/update', array('status' => "$message"));
|
|
//
|
|
}
|
|
|
|
header('Location: https://twitter.com/hashtag/CD2015');
|
|
|
|
// header('Location: ./index.php');
|
|
//} else {
|
|
//header('Location: ./clearsessions.php');
|
|
//
|