Answer the question
In order to leave comments, you need to log in
PHP VK API returns NULL. Ask for help?
I'm trying to log in from php via api vk using curl, but the response is NULL all the time.
session_start();
$request_params = array(
'client_id' => '5797533',
'redirect_uri' => 'http://oauth.vk.com/blank.html',
'scope' => 'groups,offline',
'response_type' => 'token',
'v' => '5.60',
'revoke' => '1',
'response_type' => 'code',
'display' =>'wap',
'state' => '12345'
);
$get_params = http_build_query($request_params);
$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW 64; rv:38.0) Gecko/20100101 Firefox/38.0");
curl_setopt($curl, CURLOPT_REFERER, 'http://gogle.com');
curl_setopt($curl, CURLOPT_RETURNTRANSFER , true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
//http://oauth.vk.com/oauth/authorize?redirect_uri=http%3A//oauth.vk.com/blank.html&response_type=token&client_id=5797533&scope=groups&display=wap
curl_setopt($curl, CURLOPT_URL, 'https://oauth.vk.com/oauth/authorize?client_id = 5797533 & scope = groups,offline & response_type = token redirect_uri =http://oauth.vk.com/blank.html ' );
$response1 = curl_exec($curl);
curl_close($curl);
$response1 = json_decode($response1, true);
dd($response1);
Answer the question
In order to leave comments, you need to log in
У Вас там точно проблемы с пробелами в CURLOPT_URL.
Выведите значение $response1 до json_decode. Что вернёт curl_exec (с учётом фикса пробелов)?
Json decode как раз возвращает нул, если произошка ошибка декодирования. Значит vk вернул не json а сообщение о ошибке
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question