/** * Execute the console command. * * @return mixed */ public function handle() { $instagram = new InstagramAPI(); foreach (\App\Supplier::all() as $supplier) { $instagram->setAccessToken($supplier->instagramAccount->access_token); foreach ($supplier->products()->where('is_active', true)->get() as $product) { $comments = $instagram->getMediaComments($product->instagram->id); if ($comments->meta->code == 200) { $lastScannedComment = null; for ($i = count($comments->data) - 1; $i >= 0; $i--) { $comment = $comments->data[$i]; if ($lastScannedComment == null) { $lastScannedComment = $comment->id; } if ($product->instagram->last_scanned_comment >= $comment->id) { break; } if (strpos(mb_strtolower($comment->text, 'UTF-8'), 'sepete at') !== false) { if ($customer = \App\InstagramAccount::where('instagram_id', $comment->from->id)->first()) { if ($customer->isCustomer()) { $customer = $customer->instagramable; \App\WishedProduct::create(['customer_id' => $customer->id, 'product_id' => $product->id, 'count' => 1]); } } } } if ($lastScannedComment != null) { $productInstagram = $product->instagram; $productInstagram->last_scanned_comment = $lastScannedComment; $productInstagram->update(); } } } } }
public function listMedia($username, Request $request) { $page = $request->all(); $wrap = isset($page['wrap']) ? $page['wrap'] : InstagramMedia::WRAP; $account = InstagramAccount::where('username', '=', $username)->with('InstagramMedia')->first(); if (!is_null($account)) { $media = $account->InstagramMedia()->select('id', 'photo_url', 'photo_caption', 'likes_count', 'comments_count')->paginate($wrap)->toArray(); $data = array_pop($media); return json_encode(['pagination' => $media, 'meta' => ['code' => 200], 'data' => $data]); } else { return json_encode(['meta' => ['error_type' => InstagramAccount::GRABBER_ACCOUNT_MEDIA_LIST_EMPTY, 'code' => 404, 'error_message' => 'Grabber account not exist or media list are empty']]); } }
public function callback(Request $request) { if (Session::get('instagram_operation')) { $instagramOperation = Session::pull('instagram_operation'); if ($instagramOperation['operation'] == 'login') { if ($request->get('code')) { $code = $request->get('code'); $instagram = new InstagramAPI(); $data = $instagram->getOAuthToken($code); $instagramAccount = InstagramAccount::where(['username' => $data->user->username, 'access_token' => $data->access_token])->first(); if ($instagramAccount) { if (Auth::loginUsingId($instagramAccount->instagramable->user->id)) { if ($instagramAccount->instagramable->user->isSupplier()) { return redirect()->action('Dashboard\\SupplierController@show'); } if ($instagramAccount->instagramable->user->isCustomer()) { return redirect()->action('Dashboard\\CustomerController@show'); } } } else { return redirect()->action('AuthenticationController@showRegister')->withErrors(['messages' => "Kayıtlı Kullanıcı Bulunamadı"]); } } } if ($instagramOperation['operation'] == 'register') { if ($instagramOperation['user_type'] == 'supplier') { if (Session::has('user_instagram_info')) { Session::forget('user_instagram_info'); } if ($request->get('code')) { $code = $request->get('code'); $instagram = new InstagramAPI(); $data = $instagram->getOAuthToken($code); Session::put('user_instagram_info', $data); return Redirect::action('Dashboard\\SupplierController@create'); } } if ($instagramOperation['user_type'] == 'customer') { if (Session::has('user_instagram_info')) { Session::forget('user_instagram_info'); } if ($request->get('code')) { $code = $request->get('code'); $instagram = new InstagramAPI(); $data = $instagram->getOAuthToken($code); Session::put('user_instagram_info', $data); return Redirect::action('Dashboard\\CustomerController@create'); } } } } }