/** * @return array|null */ public function getGroupInfo() { $this->response = $this->client->api('groups.getById', ['group_ids' => -$this->ownerId, 'fields' => 'city,country,place,description,wiki_page,members_count,counters,start_date, finish_date,can_post,can_see_all_posts,activity,status,contacts,links, fixed_post,verified,site,ban_info']); return $this->response(); }
public function run() { DB::table('users')->delete(); $VK = new VK(env('VK_APP_ID'), env('VK_KEY_SECRET')); $vkCountries = $VK->api('database.getCountries', ['need_all' => 1, 'count' => 1000, 'lang' => 'ru']); foreach ($vkCountries['response'] as $country) { Country::create(['id' => $country['cid'], 'title' => $country['title']]); } }
public function accessTokenByCode(Request $request, $code) { $appId = \Config::get('vk_app.appId'); $appSecret = \Config::get('vk_app.appSecret'); $vk = new VK($appId, $appSecret); try { $getAccessToken = $vk->getAccessToken($code, 'https://oauth.vk.com/blank.html'); $accessToken = $getAccessToken['access_token']; } catch (VKException $e) { $accessToken = 'error!'; } return view('oauth.accessToken', ['accessToken' => $accessToken]); }
public function index() { $appId = \Config::get('vk_app.appId'); $appSecret = \Config::get('vk_app.appSecret'); $permissions = \Config::get('vk_app.permissions'); $accessToken = \Config::get('vk_app.access_token'); $vk = new VK($appId, $appSecret, $accessToken); $dialogs = $vk->api('messages.getDialogs'); $dialogs = $dialogs['response']; $dialogs_count = array_shift($dialogs); $all_user_dialogs_ids = array(); foreach ($dialogs as $key => $value) { if (isset($value['chat_id'])) { continue; } $all_user_dialogs_ids[] = $value['uid']; } $messagesGetHistory = function ($user_id, $offset, $count) use($vk) { $messages_part = $vk->api('messages.getHistory', array('user_id' => $user_id, 'offset' => $offset, 'count' => $count)); $response = $messages_part['response']; $count = array_shift($response); return ['count' => $count, 'messages' => $response]; }; $messagesByUsers = array_fill_keys($all_users_dialogs, array()); $step = 200; foreach ($all_users_dialogs as $user_id) { $offset = 0; $count = $step; $hasMessages = true; while ($hasMessages) { $response = $messagesGetHistory($user_id, $offset, $count); $messagesPart = $response['messages']; $tempCount = $response['count']; $hasMessages = $tempCount >= $offset + $step; $offset += $step; $messagesByUsers[$user_id] = array_merge($messagesByUsers[$user_id], $messagesPart); sleep(1); } echo "<pre>"; var_export($messagesByUsers); echo "</pre>"; die; } }
public function login(UserRepository $userRepo, Guard $auth) { $vk = new vk(env('VK_CLIENT_ID'), env('VK_CLIENT_SECRET')); try { $access_token = $vk->getAccessToken($_REQUEST['code'], env('VK_REDIRECT')); $data = $vk->api('users.get', ['uids' => $access_token['user_id'], 'fields' => 'first_name,last_name,photo_big,status,screen_name']); $user = $userRepo->findOrCreate($data['response'][0]); } catch (VKException $e) { Flash::error(trans('exceptions.auth.vk_exception')); return redirect($this->default_redirect); } $this->auth->login($user, true); if (!Session::has('user')) { Session::set('user', $user); } if (url()->previous() && strpos(url()->previous(), url('/')) !== false && url()->previous() != route('auth')) { return redirect(url()->previous()); } return redirect($this->default_redirect); }
/** * @param $aid * @param $oid * @param null $captchaSid * @param null $captchaKey * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function importSong($aid, $oid, $captchaSid = null, $captchaKey = null) { if (Request::ajax()) { if (!$this->checkStepAuth('step_four')) { return Response::json(array('response' => array('status' => 'error', 'message' => 'Token Auth failed'))); } if ((int) $aid === 0 || (int) $oid === 0) { return Response::json(array('response' => array('status' => 'error', 'message' => 'Audio or Author id is wrong'))); } $songsToImport = Session::get('vk.songsToImport'); if (!is_array($songsToImport) || !count($songsToImport)) { return Response::json(array('response' => array('status' => 'error', 'message' => 'Song session was not set. Please follow all steps again'))); } if ((int) Session::get('vk.songsToImport.' . $aid . 'status') === 1) { return Response::json(array('response' => array('status' => 'success', 'message' => 'Song already imported'))); } $config = array('v' => '2.0', 'aid' => $aid, 'oid' => $oid); if ($captchaKey && $captchaSid) { $config['captcha_sid'] = $captchaSid; $config['captcha_key'] = $captchaKey; } $res = $this->vk->api('audio.add', $config); if (array_key_exists('response', $res)) { Session::put('vk.songsToImport.' . $aid . '.status', 1); return Response::json(array('response' => array('status' => 'success', 'message' => 'Song imported'))); } if (array_key_exists('error', $res)) { if ($res['error']['error_code'] == 14) { return Response::json(array('response' => array('status' => 'error', 'message' => $res['error']['error_msg'], 'captcha_sid' => $res['error']['captcha_sid'], 'captcha_img' => $res['error']['captcha_img'], 'method' => 'audio-add', 'aid' => $aid, 'oid' => $oid))); } else { return Response::json(array('response' => array('status' => 'error', 'message' => $res['error']['error_msg']))); } } return Response::json(array('response' => array('status' => 'error', 'message' => 'vk response code unsupported'))); } return redirect('/'); }