public function getPostFBPage() { $record = FbFeed::whereNull('shared')->select(DB::raw('id, fb_id, name, message, picture, category_id, type, source, object_id, created_at, DATE(created_at) AS per_day'))->where('like_count', '>', 700)->orderBy('per_day', 'DESC')->first(); if (!$record) { return Response::json(array('status' => 'error', 'data' => 'Error'), 500); } $result = new \stdClass(); $result->message = $record->message; $result->link = FbPage::get_feed_infor($record->fb_id); $result->original_link = $record->link; $result->type = $record->category->name; $tag = strtolower(trim(str_replace(' ', '_', $result->type))); $message = $record->name ? $record->name : $record->message; $message = $message . "\n\n\nLink gốc: " . $result->original_link . "\nNhóm: " . TAG . $tag; $attachment = array('access_token' => PAGE_TOKEN, 'message' => $message, 'link' => $result->link); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, FbPage::$api_url . PAGE_ID . "/feed"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output $post = curl_exec($ch); curl_close($ch); $post = json_decode($post); if (!empty($post->id)) { $record->shared = $post; } else { $record->shared = '0'; } $record->save(); return Response::json(array('status' => 'success', 'data' => $result), 200); }