A
A
Ayk722014-05-04 20:34:27
PHP
Ayk72, 2014-05-04 20:34:27

Curl for oauth.vk.com

Good evening!
Help, please, I've been trying to get an access_token from VK all day.
Here is the code I tried:

$c = file_get_contents('https://oauth.vk.com/access_token?client_id={id}&client_secret={key}&code='.$code.'&redirect_uri={site}');

but got an error:
Warning: file_get_contents(https://oauth.vk.com/access_token?client_id={id}..): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in ...

I searched on the Internet what is possible through cUrl, but I can't write the code.
Please help me write a php request.
Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
timurmusharapov, 2015-04-02
@timurmusharapov

Hey!
Just today I was interested in this issue myself, and found this solution:
function get_curl($url) {
if(function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
return $output;
} else {
return file_get_contents($url);
}
}
And you apply this function to your link instead of file_get_contents.

C
CGS, 2014-05-04
@CGS

Is that how you make a request?
client_id={id}

A
Alexander Zelenin, 2014-05-04
@zelenin

https://github.com/zelenin/VK

A
Alexander N++, 2014-05-04
@sanchezzzhak

https://oauth.vk.com/authorize?client_id='+String(VK_APP_ID)+'&scope=offline&redirect_uri=https://oauth.vk.com/blank.html=mobile&response_type=token

response_type = code and redirect_uri change for yourself, since the above link is only for applications, js and mobile authorization

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question