コード例 #1
0
 public function ajax_reserve_retweet()
 {
     if (!$this->isAjax()) {
         echo 'no ajax';
         exit;
     }
     $request = $this->RequestObj;
     $select_img = $request->select_img;
     foreach ($select_img as &$img_url) {
         list($img_url, ) = explode('?', $img_url);
     }
     $this->Session['select_img'] = $select_img;
     $this->Session['retweet_comment'] = $request->comment;
     $this->Session['retweet_link'] = $request->affiliateUrl;
     $this->Session['retweet_time'] = $request->retweet_time;
     $this->Session['aff_rakuten_account_id'] = $request->aff_rakuten_account_id;
     $this->Session['aff_retweet_reserve_info'] = $this->get_RetweetReserveInfo($this->Session['aff_rakuten_account_id']);
     $this->aff_rakuten_account_info = $this->get_RakutenAccountInfo($this->Session['aff_rakuten_account_id']);
     //affアカウントがセットされているかチェック
     $this->check_setAffAcount();
     $twObj = new TwitterOAuth($this->aff_rakuten_account_info->tw_consumer_key, $this->aff_rakuten_account_info->tw_consumer_secret, $this->aff_rakuten_account_info->tw_access_token, $this->aff_rakuten_account_info->tw_access_token_secret);
     //画像セット
     $media_ids = array();
     foreach ($this->Session['select_img'] as $select_img_url) {
         $mes = '画像アップロード URI:' . $select_img_url . "\n";
         error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile);
         if ($media_id = $this->Media_Upload($twObj, $select_img_url)) {
             $media_ids[] = $media_id;
         }
     }
     //ショートURL生成
     $short_url = $this->make_short_url($this->Session['retweet_link']);
     //ツイート処理
     $statusesUpdateObj = new statuses_update($twObj);
     $option = array("status" => $this->Session['retweet_comment'] . $short_url, "possibly_sensitive" => false, "trim_user" => true);
     if (count($media_ids)) {
         $option["media_ids"] = implode(',', $media_ids);
     }
     //var_dump($option);
     $api_res = $statusesUpdateObj->setOption($option)->Request();
     //テスト用
     $apiErrorObj = new Api_Error($api_res);
     if ($apiErrorObj->error) {
         $this->Session['result'] = 'Error';
         $this->Session['result_message'] = $apiErrorObj->errorMes_Str;
         $this->Session['tweet_id'] = '';
         $this->Session['reserve_id'] = null;
         $this->setSession();
         header('Content-Type: application/json');
         echo json_encode($this->Session);
         exit;
     }
     $item_info = $this->Session['search_item_result'][$this->Session['select_item_index']];
     $res = $this->setReserveRetweet($api_res->id_str, $item_info['itemName'], $item_info['shopName']);
     if ($res) {
         $this->Session['result'] = 'Success';
         $this->Session['result_message'] = '正常にツイートできました';
         $this->Session['tweet_id'] = $api_res->id_str;
         $this->Session['reserve_id'] = $res;
         $this->setSession();
         header('Content-Type: application/json');
         echo json_encode($this->Session);
         exit;
     } else {
         $this->Session['result'] = 'Error';
         $this->Session['result_message'] = '予約テーブル挿入エラー';
         $this->Session['tweet_id'] = $api_res->id_str;
         $this->Session['reserve_id'] = null;
         $this->setSession();
         header('Content-Type: application/json');
         echo json_encode($this->Session);
         exit;
     }
 }
コード例 #2
0
 public function Article_Tweet()
 {
     //twOBJセット
     $this->setTwObj();
     //画像があればアップロードしてメディアID取得
     $media_id = null;
     if (!is_null($this->Article_Info->image_url) and strlen($this->Article_Info->image_url)) {
         $media_id = $this->Media_Upload();
     }
     //ツイート処理
     $tw_mes = $this->Article_Info->title . " " . $this->Site_Info->site_url;
     $statusesUpdateObj = new statuses_update($this->twObj);
     $option = array("status" => $tw_mes, "possibly_sensitive" => false, "trim_user" => true);
     if ($media_id) {
         $option["media_ids"] = $media_id;
     }
     $api_res = $statusesUpdateObj->setOption($option)->Request();
     $apiErrorObj = new Api_Error($api_res);
     if ($apiErrorObj->error) {
         $mes = $apiErrorObj->errorMes_Str;
         error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile);
     } else {
         $this->tweet_id = $api_res->id_str;
         $mes = 'ツイート成功 feed_id:' . $this->Article_Info->id . ' site:' . $this->Site_Info->site_name . ' retweet_id:' . $apires->id_str . "\n";
         error_log($mes, 3, _TWITTER_LOG_PATH . $this->logFile);
     }
     //tw済みフラグセット
     $this->updateTwtedFlg();
 }