Answer the question
In order to leave comments, you need to log in
How to use VK API using php?
Banal example:
$params = array(
'user_ids' => 1,
);
$url = 'https://api.vk.com/method/users.get'.http_build_query($params);
$res = file_get_contents($url);
Answer the question
In order to leave comments, you need to log in
Most likely your server ip is banned by VK. This is very possible if you have shared-hosting, not vps. Just check with file_get_contents("vk.com")
https://github.com/bocharsky-bw/vkontakte-php-sdk
https://github.com/mordehaigerman/VKontakte-PHP-SDK
<?php
$params = array(
'user_ids' => 1,
);
$url = 'https://api.vk.com/method/users.get?'.http_build_query($params);
$res = file_get_contents($url);
function getUrl($url, $params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function getMethod($method, $params) {
$url = method_url.$method;
$params = http_build_query($params)."&lang=".method_lang;
$response = getUrl($url, $params);
return json_decode($response, true);
}
$params = array('access_token' => "token");
$result = getMethod("vk.method", $params);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question