J
J
jenya77712016-12-27 22:20:00
PHP
jenya7771, 2016-12-27 22:20:00

How to remove the error when working with file_get_contents?

I’m asking the 2nd question with errors for this code, alas, I can’t solve the problem on my own, please help

$params = array(
            'client_id' => '0000000',
            'client_secret' => '11111111111111111111111',
            'redirect_uri' => 'url_red',
            'code' => $_GET['code']
        );

         $token = file_get_contents('https://oauth.vk.com/access_token?' . http_build_query($params, null, '&'));
         //ответ будет такой {"access_token":"****","expires_in":"*****","user_id":"*****","email":"****"}
        $token = json_decode($token, true);

        $id = $token['user_id'];

         $data = file_get_contents('https://api.vk.com/method/users.get?user_ids=' . $token['user_id'] . '&lang=0&fields=photo_50,city,sex&v=5.60');
        $data = json_decode($data, true);
        $data = current($data['response']);
        //"{"response":[{"id":**,"first_name":"***","last_name":"**","photo_100":"****","hidden":1}]}"

This code works if I do it simply through files, but when I do it in conjunction with Angular, I get this
Warning error : file_get_contents( http://oauth.vk.com/access_token?client_id=5793963... failed to open stream: HTTP request failed!HTTP/1.1 401 Unauthorized
in /activation.php on line 10

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2016-12-27
@ThunderCat

If you carefully look at the text of the error, moreover, if you just go to the URL indicated in the error, it will become clear that the protocol used (http) is not suitable for authorization, which Angular apparently does not know about, see where your ang messes up with the request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question