M
M
mindnomind2014-05-19 16:54:50
PHP
mindnomind, 2014-05-19 16:54:50

How to get a token for vk.com using curl?

Friends, your help is needed. You need to get a token from vk.com via a link like this using curl:

$url= 'https://oauth.vk.com/access_token?client_id=<id>6&client_secret=<secret>&grant_type=client_credentials';

If I use the following construct:
$token = file_get_contents($url);
print_r(json_decode($token));

then the information is correctly displayed:
stdClass Object ( [access_token] => ce06f81fce06f81fce034a4ac1ce445683cce06ce06f81f9d7cf3f6cb5400f087158620 [expires_in] => 0 )

But still I would like to receive a token using curl. I'm building something like this:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result=curl_exec($ch);
curl_close($ch);
print_r(json_decode($result));

and I don't get anything. What am I doing wrong?
Thank you in advance for your help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mindnomind, 2014-05-20
@mindnomind

Lord, I'm sorry.
As it turned out, the curl package was simply not installed on the server. This was the reason - but I did not notice the elephant.
Thanks to all.

A
Alexander Zelenin, 2014-05-19
@zelenin

https://github.com/zelenin/VK

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question