function PostImage() { if (!isset($_POST['source']) || $_POST['source'] == "") { return "Missing required params"; } $config = (include "/config.php"); $source = $_POST['source']; $final = ""; if (isset($_POST['message'])) { $orig = $_POST['message']; $final = FilterText($orig); } $access_token = $_SESSION['access_token']; $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); $check = new TB_Twitter_Check(); if (!$check->VerifyTweet($source, $final)) { return "Tweet is not valid"; exit; } $media1 = $connection->upload('media/upload', array('media' => $source)); $parameters = array('status' => $final, 'media_ids' => implode(',', array($media1->media_id_string))); $result = $connection->post('statuses/update', $parameters); if ($connection->getLastHttpCode() == 200) { return "success"; } else { return "An unnknown error occured"; } }
public function testPostStatusesUpdateWithMedia() { $this->twitter->setTimeouts(60, 30); // Image source https://www.flickr.com/photos/titrans/8548825587/ $file_path = __DIR__ . '/kitten.jpg'; $result = $this->twitter->upload('media/upload', array('media' => $file_path)); $this->assertEquals(200, $this->twitter->getLastHttpCode()); $this->assertObjectHasAttribute('media_id_string', $result); $parameters = array('status' => 'Hello World ' . time(), 'media_ids' => $result->media_id_string); $result = $this->twitter->post('statuses/update', $parameters); $this->assertEquals(200, $this->twitter->getLastHttpCode()); if ($this->twitter->getLastHttpCode() == 200) { $result = $this->twitter->post('statuses/destroy/' . $result->id_str); } return $result; }
public function testPostStatusesUpdateWithMediaChunked() { $this->twitter->setTimeouts(60, 30); // Video source http://www.sample-videos.com/ $file_path = __DIR__ . '/video.mp4'; $result = $this->twitter->upload('media/upload', array('media' => $file_path, 'media_type' => 'video/mp4'), true); $this->assertEquals(201, $this->twitter->getLastHttpCode()); $this->assertObjectHasAttribute('media_id_string', $result); $parameters = array('status' => 'Hello World ' . time(), 'media_ids' => $result->media_id_string); $result = $this->twitter->post('statuses/update', $parameters); $this->assertEquals(200, $this->twitter->getLastHttpCode()); if ($this->twitter->getLastHttpCode() == 200) { $result = $this->twitter->post('statuses/destroy/' . $result->id_str); } return $result; }
<?php //Bibliotecas necesarias. require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; //Key de la aplicacion de twitter. $consumerKey = 'uNF8aNETIfskqNsMMkybIA'; $consumerSecret = 'bB33A8QBz97AdEw9UpcSHxwrv586Pf2Mujy4tYBdi8M'; $access_token = '216136539-EGLcwsMTS8DH12WaPYSKZuid4wWbh1jxcuxL90eo'; $access_token_secret = 'ijWStO34zLQtU1kKGYXt6aybM3hK5FqKxTiJYwHORR1lg'; //Conexiones a twitter. $connection = new TwitterOAuth($consumerKey, $consumerSecret, $access_token, $access_token_secret); $content = $connection->get("account/verify_credentials"); //Obtenemos todas las imagenes del subreddit. $json = file_get_contents('https://www.reddit.com/r/pics.json'); $obj = json_decode($json); //Generamos un numero aleatorio. $randomInt = rand(1, 25); //Obtenemos la url de la imagen aleatoria. $img = $obj->data->children[$randomInt]->data->preview->images[0]->source->url; //Agregamos la imagen. $media1 = $connection->upload('media/upload', ['media' => $img]); $parameters = ['status' => 'Probando...', 'media_ids' => implode(',', [$media1->media_id_string])]; //Postemos el tweet y obtenemos su resultado. $result = $connection->post('statuses/update', $parameters);
<?php require_once 'twitter/common.php'; require_once 'twitter/twitteroauth/autoload.php'; use Abraham\TwitterOAuth\TwitterOAuth; include "header.php"; $access_token = $_SESSION['access_token']; // OAuthトークンとシークレットも使って TwitterOAuth をインスタンス化 $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); $media_id = $connection->upload("media/upload", array("media" => $_POST["file_name"])); $parameters = array('status' => $_POST["Insert"] . " " . $_POST["tweet"] . " #デレステ", 'media_ids' => $media_id->media_id_string); $result = $connection->post('statuses/update', $parameters); echo "<br />ツイートを試みました。Twitterを確認してみてください。<br /><hr>"; echo "当サイト公式アカウントのフォローをお願いしますm(_ _)m<br />"; ?> <a href="https://twitter.com/fcMgt4slStage" class="twitter-follow-button" data-show-count="false" data-size="large" data-show-screen-name="false">Follow @fcMgt4slStage</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> <img style="width: 100%;" src="<?php echo $_POST["file_name"]; ?> " alt="img" /> <?php include "footer.html"; ?> </body> </html>
/* ** Example call: http://freelabel.net/social-test/?a=uploadmedia&f=freelabel.net/images/fllogo.png */ if ($_GET == '') { // NO PARAMTERS FOUND! echo 'Error: No Parameters Set!'; } else { $debug[] = 'Params: <pre>'; switch ($_GET['a']) { case 'uploadmedia': // confirm that file parameters are set $debug[] = 'Media Upload Initialized<br>'; if ($_GET['f'] != '' and $_GET['t'] != '') { $uploadedmedia = 'http://' . str_replace(' ', '%20', $_GET['f']); $debug[] = 'photos detected: "' . $uploadedmedia . '"'; $media1 = $connection->upload('media/upload', array('media' => $uploadedmedia)); if (strlen($_GET['t']) > 90) { $text = substr($_GET['t'], 0, 90) . '...'; } else { $text = $_GET['t']; } $parameters = array('status' => $text, 'media_ids' => $media1->media_id_string); $content = $connection->post('statuses/update', $parameters); //print_r($content->entities->media[0]->display_url); $twitpic = $content->entities->media[0]->display_url; $debug[] = $media1; $debug[] = $content; //$twitpic = $media1; //return $twitpic; } else { echo 'No File or Text Found Found!<br>Please use &f=[] and &t=[]<br>';
<?php require "./vendor/autoload.php"; require "./config.php"; use Abraham\TwitterOAuth\TwitterOAuth; $connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET, $ACCESS_TOKEN, $ACCESS_TOKEN_SECRET); $media = $connection->upload('media/upload', array('media' => 'img/11222510.png')); $parameters = array('status' => 'image upload test', 'media_ids' => $media->media_id_string); $result = $connection->post('statuses/update', $parameters); var_dump($result);
function postToTwitter($message, $mediaURL = null) { $tag = str_replace(' ', '', SYSTEM_SITE_NAME . SYSTEM_YEAR); $message = $message . ' #' . $tag; if (strlen($message) > 140) { return false; } $connection = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET); $params = ['status' => $message]; if ($mediaURL) { $mediaURL = unshorten_url($mediaURL); $media = $connection->upload('media/upload', ['media' => $mediaURL]); if ($media) { $params['media_ids'] = $media->media_id_string; } } return $connection->post("statuses/update", $params); }
$emotion = str_replace("_slash_", "/", $emotion); $emotion = str_replace("_greaterthan_", ">", $emotion); $emotion = str_replace("_lessthan_", "<", $emotion); $emotion = str_replace("_asterix_", "*", $emotion); $emotion = str_replace("_period_", ".", $emotion); $emotion = str_replace("_caret_", "^", $emotion); return $emotion; } $images = scandir("./images/"); $filename = false; foreach ($images as $image) { if (strpos($image, '.jpg') !== false) { $filename = $image; break; } } if ($filename) { $e = substr($filename, 10, strpos($filename, ".jpg") - 10); $e = decodeEmotion($e); $connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); $media1 = $connection->upload('media/upload', ['media' => "./images/" . $filename]); $parameters = ['status' => $e, 'media_ids' => $media1->media_id_string]; $status = $connection->post("statuses/update", $parameters); if (!rename("./images/" . $filename, "./posted/" . $filename)) { echo "File action error."; exit; } echo $filename . " posted."; } else { echo "No files queued."; }
$access_token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $_REQUEST['oauth_verifier']]); // echo 'last api path: ' . $connection->getLastApiPath() . '<br>'; // echo 'server code: ' . $connection->getLastHttpCode() . '<br>'; // echo 'body: '; // print_r($connection->getLastBody()); // echo '<br>'; //Put the access token in session $_SESSION['access_token'] = $access_token; //Make a new connection with the user's access token $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); //Verify authentication was successful $user = $connection->get("account/verify_credentials"); // echo 'last api path: ' . $connection->getLastApiPath() . '<br>'; // echo 'server code: ' . $connection->getLastHttpCode() . '<br>'; // echo 'body: '; // print_r($connection->getLastBody()); // echo '<br>'; //Upload media (this session variable was set elsewhere) $media1 = $connection->upload('media/upload', ['media' => $_SESSION['img_url']]); //Debug last connection call // echo 'last api path: ' . $connection->getLastApiPath() . '<br>'; // echo 'server code: ' . $connection->getLastHttpCode() . '<br>'; // echo 'body: '; // print_r($connection->getLastBody()); // echo '<br>'; //Set the parameters for creating a new Tweet with an image $parameters = ['status' => $_SESSION['message-text'], 'media_ids' => $media1->media_id_string]; //Post new Tweet status and image $connection->post('statuses/update', $parameters); //Reroute to original page header('Location: http://worldsneakerchampionship.com/join-us');
/** * Send Tweet through Twitter API * * @return Void */ public function send() { /** * Initiate new Twitter */ $twitter = new TwitterOAuth(env('CONSUMER_KEY'), env('CONSUMER_SECRET'), env('ACCESS_TOKEN'), env('ACCESS_SECRET')); /** * Get Tweets from Queue */ $tweets = $this->next(); /** * Collate Responses */ $results = array(); /** * Generate Images and Upload/Send each Tweet */ foreach ($tweets as $tweet) { // Get Name $name = Admin::name($tweet->target); // Get Target Handle $target = Targets::find($tweet->target); $handle = $target->handle; // Remove Linebreaks from Message $tweet->message_clean = str_replace(array("\r", "\n"), ' ', $tweet->message_clean); if (trim($name) != '' && trim($tweet->message_clean != '')) { // Generate Image Image::setDetails($name, $tweet->message_clean); $image = Image::paintImage(); $details = Image::saveImage($image); // Save Tweet with Image URL $tweet->image_url = $details['image_url']; $tweet->save(); // The Message $hashtag = '#tweetthelove'; $message = '@' . $handle . ' ' . $tweet->message_clean . ' ' . $hashtag; // Upload to Twitter $media = $twitter->upload('media/upload', ['media' => $details['image_url']]); if (isset($media->media_id_string)) { // Post Tweet $status = $twitter->post('statuses/update', ['status' => $message, 'media_ids' => $media->media_id_string]); } if ($twitter->getLastHttpCode() === 200) { // Mark as Sent $tweet->sent = 1; $tweet->save(); $result = true; } else { $tweet->failed = 1; $tweet->save(); $result = json_encode($twitter->getLastBody()); } } else { $tweet->failed = 1; $tweet->save(); $result = false; } $results[$tweet->id] = array('status' => $result, 'message' => $message); } return $results; }
<?php session_start(); require 'autoload.php'; use Abraham\TwitterOAuth\TwitterOAuth; define('CONSUMER_KEY', ''); // add your app consumer key between single quotes define('CONSUMER_SECRET', ''); // add your app consumer secret key between single quotes define('OAUTH_CALLBACK', 'https://sohaibilyas.com/twapp/callback.php'); // your app callback URL if (!isset($_SESSION['access_token'])) { $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET); $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK)); $_SESSION['oauth_token'] = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token'])); echo $url; } else { $access_token = $_SESSION['access_token']; $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); // getting basic user info $user = $connection->get("account/verify_credentials"); // printing username on screen echo "Welcome " . $user->screen_name; // uploading media (image) and getting media_id $tweetWM = $connection->upload('media/upload', ['media' => 'https://pbs.twimg.com/profile_images/695720184464740353/lnOGP0Z8_400x400.jpg']); // tweeting with uploaded media (image) using media_id $tweet = $connection->post('statuses/update', ['media_ids' => $tweetWM->media_id, 'status' => 'tweeting with image file']); print_r($tweet); }
public static function Twitter(Post $post) { if (!\Yii::$app->params['twitter']) { return false; } // autoload.php does not work require_once 'protected/vendor/abraham/twitteroauth/autoload.php'; $twitter = new TwitterOAuth(ArrayHelper::getValue(\Yii::$app->params['twitter'], 'consumerKey'), ArrayHelper::getValue(\Yii::$app->params['twitter'], 'consumerSecret'), ArrayHelper::getValue(\Yii::$app->params['twitter'], 'oauthToken'), ArrayHelper::getValue(\Yii::$app->params['twitter'], 'oauthTokenSecret')); if ($data = json_decode($post->text)) { switch ($data->type) { case self::TYPE_IMAGE: $media = $twitter->upload('media/upload', ['media' => $data->src]); $statuses = $twitter->post("statuses/update", ["status" => "Новое фото " . \Yii::$app->params['siteUrl'] . 'post/' . $post->id . " #" . implode(' #', ArrayHelper::map(ArrayHelper::getValue($post, 'tags'), 'id', 'name')) . " #aaaaakz", "media_ids" => $media->media_id_string]); break; case self::TYPE_VIDEO: $statuses = $twitter->post("statuses/update", ["status" => "Новое видео " . \Yii::$app->params['siteUrl'] . 'post/' . $post->id . " #" . implode(' #', ArrayHelper::map(ArrayHelper::getValue($post, 'tags'), 'id', 'name')) . " #aaaaakz"]); break; } } else { $statuses = $twitter->post("statuses/update", ["status" => "Новый пост №" . $post->id . " " . \Yii::$app->params['siteUrl'] . 'post/' . $post->id . " #" . implode(' #', ArrayHelper::map(ArrayHelper::getValue($post, 'tags'), 'id', 'name')) . " #aaaaakz"]); } }
public function postTwitter($array) { $optionAppTwitter = get_option('twfc_app_twitter'); // realiza a conexão com o twiiter $connection = new TwitterOAuth($optionAppTwitter['twitterconsumer'], $optionAppTwitter['twitterconsumersecret'], $optionAppTwitter['twitteraccesstoken'], $optionAppTwitter['twitteraccesstokensecret']); $content = $connection->get("account/verify_credentials"); if (isset($content)) { if ($array['imagem']) { $media = $connection->upload('media/upload', array('media' => $array['imagem'])); $parameters = array('status' => $array['titulo'], 'media_ids' => $media1->media_id_string); } else { $parameters = array('status' => $array['titulo']); } $result = $connection->post('statuses/update', $parameters); return $result; } }