示例#1
0
 public function getAdSharePage()
 {
     $records = AdShare::whereRaw('status = ? AND crawl = ?', array(true, false))->take(100)->get();
     if (!count($records)) {
         AdShare::all()->update(array('crawl' => false));
         return Response::json(array('status' => 'error'), 500);
     }
     foreach ($records as $record) {
         if ($record->fb_id) {
             $link = "https://www.facebook.com/" . $record->fb_id;
             UserAccessToken::get_fb_page_infor($AdSharePage['fb_link']);
             $record->crawl = true;
             $record->save();
         }
     }
     return Response::json(array('status' => 'success'), 200);
 }
示例#2
0
 public function postFeedFB()
 {
     if (!Auth::check()) {
         return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'require_signin')), 500);
     }
     $data = post();
     $default = array('ad_id' => '', 'type' => '', 'link' => '', 'message' => '');
     $merge = array_merge($default, $data);
     $merge = \DLNLab\Classified\Classes\HelperClassified::trim_value($merge);
     extract($merge);
     // Get access token
     $user_id = Auth::getUser()->id;
     $record = UserAccessToken::valid_access_token($user_id, 'facebook');
     if (empty($record) || empty($record->access_token)) {
         return Response::json(array('status' => 'error'), 500);
     }
     $access_token = $record->access_token;
     $check = UserAccessToken::check_fb_access_token($access_token);
     if (!$check) {
         return Response::json(array('status' => 'error'), 500);
     }
     $fb_user_id = $check->user_id;
     $record = null;
     if ($fb_user_id) {
         $postdata = http_build_query(array('access_token' => $access_token, 'message' => $message, 'link' => $link, 'privacy' => array('value' => 'EVERYONE')));
         $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
         $context = stream_context_create($opts);
         $obj = json_decode(@file_get_contents(self::$graph . $fb_user_id . '/feed', false, $context));
         if (!empty($obj->id)) {
             $user_id = Auth::getUser()->id;
             $record = new AdShare();
             $record->ad_id = $ad_id;
             $record->user_id = $user_id;
             $record->link = $link;
             $record->md5 = md5($link);
             $record->share_id = $obj->id;
             $record->save();
         }
     }
     return Response::json($record);
 }