Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $login = 'login'; //Логин
- $pass = 'pass'; //Пароль
- $app = '2274003'; //id приложения для получения token
- $key = 'hHbZxrka2uZ6jB1inYsH'; //secret key приложения
- $acc_token_file='vk_acc_token.php';
- $access_token = '';
- load_token();
- api('account.setOnline');
- function load_token($reauth=false){
- global $access_token,$acc_token_file;
- if (!$reauth && file_exists($acc_token_file)) {
- $s=file_get_contents($acc_token_file);
- preg_match("/\[([a-f0-9]+)\]/", $s, $matches);
- if (!$matches[0]){
- load_token(true);
- } else {
- $access_token=$matches[1];
- }
- } else {
- auth_api();
- if ($access_token==""){
- echo "Auth Error";
- } else {
- file_put_contents($acc_token_file,'<?php if (!defined("vk_online")) die("x_X"); "['.$access_token.']";?>');
- }
- }
- }
- function curl( $url ) {
- $ch = curl_init( $url );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
- curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
- $response = curl_exec( $ch );
- curl_close( $ch );
- return $response;
- }
- function auth_api(){
- global $access_token,$app,$key,$login,$pass;
- $auth = curl( "https://oauth.vk.com/token?grant_type=password&client_id=$app&client_secret=$key&username=$login&password=$pass" ); //Авторизация
- $json = json_decode( $auth, true );
- $access_token = $json['access_token'];
- }
- function api($method){
- global $access_token;
- $r = curl("https://api.vk.com/method/$method?access_token=$access_token");
- $json = json_decode( $r, true );
- if ($json['error']){
- $code=$json['error']['error_code'];
- if ($code==4 || $code==3){
- load_token(true);
- api($method);
- } else {
- echo $r;
- }
- } else {
- echo $r;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement