I've been working on upgrading from v 1 to 1.1 for a few days now. I have 100s of users that can't see their followers in my dashboard.
I followed all the steps by changing /1/ to /1.1/ still not working.
Getting error 404 (Not Found)
Controller:
function twitter_auth()
{
if ( !$this->tweet->logged_in() )
{
die('some how you are not logged in');
}
$tokens = $this->tweet->get_tokens();
$this->tweet->enable_debug(TRUE);
$user = $this->tweet->call('get', 'account/verify_credentials');
var_dump($user);
}
$options = array(
'count' => 10,
'page' => 2,
'include_entities' => 1
);
$timeline = $this->tweet->call('get', 'statuses/home_timeline');
var_dump($timeline);
}
Jobs:
function get_twitter_subscribers($args)
{
$rate = #file_get_contents('http://api.twitter.com/1.1/application/rate_limit_status.json');
$rate = #json_decode($rate);
if($rate->remaining_hits == 0):
$status = 'retask';
else:
$new_data = #file_get_contents('http://api.twitter.com/1.1/users/show.json? screen_name='.$args['account_id'].'&include_entities=true');
$new_data = #json_decode($new_data);
if(isset($new_data->followers_count)){
$insert_args = array(
'account_id' => $args['account_id'],
'metric' => 'subscribers',
'value' => $new_data->followers_count,
'platform' => 'twitter'
);
$insert = $this->CI->metrics_model->insert_metric($insert_args);
if (isset($insert)) { $status = 'complete'; }
}else{
$this->send_error_email("Function: get_twitter_subscribers - new_data->followers_count not set for account id: " . $args['account_id'] . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'http://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
}
endif;
if(!isset($status)){
$this->send_error_email("Function: get_twitter_subscribers - status not set." . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'http://api.twitter.com/1.1/users/show.json? screen_name='.$args['account_id'].'&include_entities=true');
$status = 'error';
}
return $status;
controllers:
function auth($platform)
{
if($platform == 'facebook'):
echo 'auth facebook';
elseif($platform == 'twitter'):
$this->load->library('tweet');
// current key in php page
$tokens = array(
'oauth_token' => 'xxxxxxxxxxxxx',
'oauth_token_secret' => 'xxxxxxxxxxxx'
);
$this->tweet->set_tokens($tokens);
if ( !$this->tweet->logged_in() ) :
$this->tweet->set_callback(site_url('manage/auth/twitter'));
$this->tweet->login();
else:
echo 'Twitter logged in. Return to manager';
endif;
endif;
}
What am I doing wrong?
This issue has been resolved. I created my own cURL library.
function get_twitter_subscribers($args){
$request = curl_init();
$bearer = "AAAAAAAAAAAAAAAAAAAAAJ%2xxxxxxxxxxxxxxx0000x0x0x0x0";
curl_setopt($request, CURLOPT_SSLVERSION, 1);
curl_setopt($request, CURLOPT_URL, 'https://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
curl_setopt($request, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$bearer));
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$new_data = json_decode($file_get_contents = curl_exec($request));
curl_close($request);
if(isset($new_data->followers_count)){
$insert_args = array(
'account_id' => $args['account_id'],
'metric' => 'subscribers',
'value' => $new_data->followers_count,
'platform' => 'twitter'
);
$insert = $this->CI->metrics_model->insert_metric($insert_args);
if (isset($insert)) { $status = 'complete'; }
}else{
$this->send_error_email("Function: get_twitter_subscribers - new_data->followers_count not set for account id: " . $args['account_id'] . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'https://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
}
if(!isset($status)){
$this->send_error_email("Function: get_twitter_subscribers - status not set." . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'http://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
$status = 'error';
}
return $status;
}
Related
I am posting the hosting order and I want to increase the "number of sales" column in my "hostings" table, but the data of all packages in my hostings table is increasing.
Here is my relevant code, I can say that there is no method I haven't tried.
$hostingdata = $this->db->query("select number_of_sales from hostings where id=" . $this->input->post('package_id'))->row();
$quantity = 1;
$new_number_of_sales = $hostingdata->number_of_sales + $quantity;
$data = array(
'number_of_sales' => $new_number_of_sales
);
$this->db->update('hostings', $data);
//FULL CODE
public function buy_hosting_post()
{
if ($this->input->post('package_id') && $this->session->userdata('id')) {
$hosting = $this->db->from('hostings')->where('id', $this->input->post('package_id'))->get()->row_array();
if ($hosting) {
$data = array(
'user_id' => $this->session->userdata('id'),
'domain' => $this->input->post('domain'),
'price' => $this->input->post('price'),
// 'end_date' => date('Y-m-d h:i:s',$end_date),
'package_id' => $hosting['id'],
'package_title' => $hosting['name'],
'payment_status' => 0,
);
$this->db->insert('hosting_orders', $data);
$hostingdata = $this->db->query("select number_of_sales from hostings where id=" . $this->input->post('package_id'))->row();
$quantity = 1;
$new_number_of_sales = $hostingdata->number_of_sales + $quantity;
$data = array(
'number_of_sales' => $new_number_of_sales
);
$this->db->update('hostings', $data);
$hosting_order_successful = array(
'hosting_order_successful' => 'success',
);
$this->session->set_userdata('hosting_order_successful', $hosting_order_successful);
redirect(("hosting-siparisi-olusturuldu"));
} else {
redirect(base_url());
}
} else {
redirect(base_url());
}
}
I solved the problem in the following way, but it makes the system heavy.
$hostingdata = $this->db->query("select number_of_sales from hostings where id=" . $this->input->post('package_id'))->row();
$quantity = 1;
$new_number_of_sales = $hostingdata->number_of_sales + $quantity;
$data = array(
'number_of_sales' => $new_number_of_sales
);
$this->db->where('id', $this->input->post('package_id')); // added here.
$this->db->update('hostings', $data);
how do I integrate the multipart upload of s3? I am uploading to s3 and everything works. just I want to refactor the code to S3 multipart upload because the files are too large on the server
// Amazon checking folder
$directory = 'Case/'. $caseDir;
foreach ($request->file('fileslab') as $s3file) {
// Getting request names & extension
$s3patientFirstName = $request->patient_firstname;
$s3patientLastName = $request->patient_lastname;
$s3SavedOrigName = $s3file->getClientOriginalName();
$SendFileToS3 = $s3patientFirstName . '_' . $s3patientLastName . '_' . time() . $s3SavedOrigName;
$contents = file_get_contents($dbfile->getRealPath());
$path = Storage::disk('s3')->put($directory. '/' .$SendFileToS3, $contents);
if (!Storage::disk('s3')->exists($directory)){
Storage::disk('s3')->makeDirectory($directory);
$path = Storage::disk('s3')->put( $directory. '/' . $SendFileToS3, $contents );
}else{
$path = Storage::disk('s3')->put( $directory. '/' .$SendFileToS3, $contents);
}
The Amazon SK Example is below:
require 'vendor/autoload.php';
use Aws\Common\Exception\MultipartUploadException;
use Aws\S3\MultipartUploader;
use Aws\S3\S3Client;
$bucket = '*** Your Bucket Name ***';
$keyname = '*** Your Object Key ***';
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-1'
]);
// Prepare the upload parameters.
$uploader = new MultipartUploader($s3, '/path/to/large/file.zip', [
'bucket' => $bucket,
'key' => $keyname
]);
// Perform the upload.
try {
$result = $uploader->upload();
echo "Upload complete: {$result['ObjectURL']}" . PHP_EOL;
} catch (MultipartUploadException $e) {
echo $e->getMessage() . PHP_EOL;
}
I fixed it.
foreach ($request->file('fileslab') as $s3file) {
$directory = 'Case/'. $caseDir;
$contents = fopen($s3file, 'rb');
$s3patientFirstName = $request->patient_firstname;
$s3patientLastName = $request->patient_lastname;
$s3SavedOrigName = $s3file->getClientOriginalName();
$SendFileToS3 = $s3patientFirstName . '_' . $s3patientLastName .
'_' . time() . $s3SavedOrigName;
$disk = Storage::disk('s3');
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-west-1'
]);
$uploader = new MultipartUploader($s3, $contents, [
'bucket' => $_ENV['AWS_BUCKET'],
'key' => $SendFileToS3,
]);
try {
$result = $uploader->upload();
} catch (MultipartUploadException $e) {
return $e->getMessage();
}
}
```
am trying to capture all queries and record a log of interactions, however some queries are not being captured, this specific query for example:
$this->db->update('showtec.motoristas', $motorista);
I capture the queries using the Hooks function like this:
Hooks.php:
$hook['post_controller'] = array(
'class' => 'Db_query_log',
'function' => 'log_db_queries',
'filename' => 'db_log.php',
'filepath' => 'hooks'
);
db_log.php:
<?php
class Db_query_log {
function __construct() {
}
function log_db_queries() {
$CI =& get_instance();
$CI->load->model('auditoria');
$data = array();
$queries = $CI->db->queries;
$data['id_usuario_gestor'] = $CI->auth->get_login('id_user');
foreach ($queries as $query){
if (preg_match($pattern = '/' . 'INSERT' . '/', $query)){
$queryArray = explode("`", $query);
if($queryArray[3] != 'ip'){
$data['query'] = $query;
$data['clause'] = 'insert';
break;
}
}elseif (preg_match($pattern = '/' . 'UPDATE' . '/', $query)){
$data['query'] = $query;
$data['clause'] = 'update';
break;
}elseif (preg_match($pattern = '/' . 'DELETE' . '/', $query)){
$data['query'] = $query;
$data['clause'] = 'delete';
break;
}
}
if(array_key_exists('query', $data)){
$CI->auditoria->salvarAuditoria($data);
}
}
}
I'm trying to display tweets on a website built on codeigniter but can't seem to pull in the user tweets. To do this, I'm pulling the following script into my header as an include and then printing the tweet in the appropriate section with the code below. I've already set up the access tokens and consumer keys as well. Any ideas on why this is working?
Include file in header
<?php
function buildBaseString($baseURI, $method, $params) {
$r = array();
ksort($params);
foreach($params as $key=>$value){
$r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}
function buildAuthorizationHeader($oauth) {
$r = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $key=>$value)
$values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(', ', $values);
return $r;
}
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$oauth_access_token = "ACCESS TOKEN HERE";
$oauth_access_token_secret = "ACCESS TOKEN SECRET HERE";
$consumer_key = "CONSUMER KEY HERE";
$consumer_secret = "CONSUMER KEY SECRET HERE";
$oauth = array( 'oauth_consumer_key' => $consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.0'
);
$base_info = buildBaseString($url, 'GET', $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
// Make Requests
$header = array(buildAuthorizationHeader($oauth), 'Expect:');
$options = array( CURLOPT_HTTPHEADER => $header,
//CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json, false);
$latest_tweet = $twitter_data[0];
?>
Print tweet
<span class="tweet">"<?php if(!empty($latest_tweet)){echo $latest_tweet->text;} else{echo "Welcome to Time Equities!";} ?>"</span>
I am at my wits end and don't know why my code is not working . Everything seems good to me .. I have implemented a captcha in my user review function and added a verification method using callback_ .
The captcha is showing in the view and i have dumped the session data and the input field data and they are both working.
The form validation is also working in case of captcha input field but seems like the callback_check_captcha parameter is not working but the function seems fine to me .
Here is my controller
function user_review($id = null , $start = 0){
$check_id = $this->mdl_phone->get_phone_feature($id);
if ($check_id == null ) {
$data['phone_model'] = $this->get_phone_models();
$data['feature'] = null;
$data['title'] = 'Nothing Found';
$data['main_content']= 'phone/error';
echo Modules::run('templates/main',$data);
} else{
$data['phone_model'] = $this->get_phone_models();
$data['success'] = null;
$data['errors'] = null;
if($this->input->server("REQUEST_METHOD") === 'POST' ){
$this->load->library('form_validation');
$this->form_validation->set_rules('text','Review','required|xss_clean');
$this->form_validation->set_rules('captcha', 'Captcha','trim|required|callback_check_captcha');
if($this->form_validation->run() == FALSE){
$data['errors'] = validation_errors();
}else{
$user = $this->ion_auth->user()->row();
$user_id = $user->id;
$data = array(
'phone_id' => $id,
'user_id' => $user_id,
'text' => strip_tags($this->input->post('text')),
);
$this->db->insert('user_review' ,$data);
$data['phone_model'] = $this->get_phone_models();
$data['success'] = 'Your Review has been successfully posted ';
$data['errors']= null;
}
}
// Initilize all Data at once by $id
$data['feature'] = $this->mdl_phone->get_phone_feature($id);
//$data['rating'] = $this->mdl_phone->get_user_rating($id);
$data['user_review'] = $this->mdl_phone->get_user_review($id , 5 , $start);
$this->load->library('pagination');
$config['base_url'] = base_url().'phone/user_review/'.$id;
$config['total_rows'] = $this->mdl_phone->get_user_review_count($id);
$config['per_page'] = 5;
$config['uri_segment'] = 4;
$config['anchor_class'] = 'class="page" ';
$this->pagination->initialize($config);
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url().'captcha/',
'img_width' => 150,
'img_height' => 30,
);
$cap = create_captcha($vals);
$this->session->set_userdata('captcha',$cap['word']);
$data['captcha'] = $cap['image'];
$data['title'] = $this->mdl_phone->get_phone_title($id)." User Review , Rating and Popularity";
$data['main_content'] = 'phone/user_review';
echo Modules::run('templates/main',$data);
}
}
function check_captcha($cap)
{
if($this->session->userdata('captcha') == $cap )
{
return true;
}
else{
$this->form_validation->set_message('check_captcha', 'Security number does not match.');
return false;
}
}
The bellow CAPTHA working properly refer this code
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . '/captcha/'
);
$cap = create_captcha($vals);
$data = array(
'captcha_time' => $cap['time'],
'ip_address' => $this->input->ip_address(),
'word' => $cap['word']
);
$this->session->set_userdata($data);
$data['cap_img'] = $cap['image'];
I think your image url problem or you are not giving a file permission to the captha folder .