$status ='yapyzal donate fixed checking -'.$short; $tweet = $connection->post('statuses/update', array('status' => $status));*/ //$filename = "image.jpg"; //$handle = fopen($filename, "rb"); //$image = fread($handle, filesize($filename)); //fclose($handle); //$params = array('media[]' => "{$image};type=image/jpeg;filename={$filename}" , // 'status' => 'my status'); //$response =$connection->post('statuses/update_with_media', $params,true,true); /*$oauth_token=$access_token['oauth_token']; $oauth_token_secret=$access_token['oauth_token_secret']; echo $oauth_token; echo $oauth_token_secret;*/ $status = 'yapyzal donate fixed checkingdddrr'; //$tweet = $connection->post('statuses/update', array('status' => $status)); $connection->upload('statuses/update_with_media', array('media[]' => "ganesh.jpg", 'status' => "{$status}")); /*$image = '2.bp.blogspot.com/-gHMuO_huw0s/UjNEQl-fL_I/AAAAAAAAAWQ/HhqGo4MskrE/s320/srinu.jpg'; $code = $connection->request( 'POST','https://upload.twitter.com/1.1/statuses/update_with_media.json', array( 'media[]' => "@{$image};type=image/jpeg;filename={$filename}", 'status' => 'hi this is sample', ), true, // use auth true // multipart ); if ($code == 200){ tmhUtilities::pr(json_decode($connection->response['response'])); }else{ tmhUtilities::pr($connection->response['response']);
/** * Post a status update to Twitter * @param int $item_id */ public function tweet($item_id) { access::verify_csrf(); $item = ORM::factory("item", $item_id); $form = twitter::get_tweet_form($item); if ($form->validate()) { $item_url = url::abs_site($item->relative_url_cache); $user = $this->_get_twitter_user(identity::active_user()->id); $consumer_key = module::get_var("twitter", "consumer_key"); $consumer_secret = module::get_var("twitter", "consumer_secret"); require_once MODPATH . "twitter/vendor/twitteroauth/twitteroauth.php"; $connection = new TwitterOAuth($consumer_key, $consumer_secret, $user->oauth_token, $user->oauth_token_secret); $message = $form->twitter_message->tweet->value; $attach_image = $form->twitter_message->attach_image->value; if ($attach_image == 1) { $filename = APPPATH . "../var/resizes/" . $item->relative_path_cache; $handle = fopen($filename, "rb"); $image = fread($handle, filesize($filename)); fclose($handle); $response = $connection->upload('statuses/update_with_media', array('media[]' => "{$image};type=image/jpeg;filename={$filename}", 'status' => $message)); } else { $response = $connection->post('statuses/update', array('status' => $message)); } if (200 == $connection->http_code) { message::success(t("Tweet sent!")); json::reply(array("result" => "success", "location" => $item->url())); } else { message::error(t("Unable to send, your Tweet has been saved. Please try again later: %http_code, %response_error", array("http_code" => $connection->http_code, "response_error" => $response->error))); log::error("content", "Twitter", t("Unable to send tweet: %http_code", array("http_code" => $connection->http_code))); json::reply(array("result" => "success", "location" => $item->url())); } $tweet->item_id = $item_id; !empty($response->id) ? $tweet->twitter_id = $response->id : ($tweet->twitter_id = NULL); $tweet->tweet = $message; $tweet->id = $form->twitter_message->tweet_id->value; $this->_save_tweet($tweet); } else { json::reply(array("result" => "error", "html" => (string) $form)); } }
/** * Used to upload image into Twitter * (attachment to text) * * @access public * @param $image_name * @param $status * @return mixed */ public function tweet_with_image($status, $image_name) { $image_path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/public/uploads/' . $this->_user_id . '/' . $image_name; $connection = new TwitterOAuth($this->_config['consumer_key'], $this->_config['consumer_secret'], $this->_token['token1'], $this->_token['token2']); $tweet = $connection->upload('statuses/update_with_media', array('media[]' => '@' . $image_path, 'status' => $status)); return $tweet; }