API VKontakte. Requests to API and getting data
In last lesson we began to consider API VKontakte. In this lesson we’ll make our first requests to api methods and get data about vkontakte user.
We’ll make request with several ways – javascript, jquery ajax and php.
We’ll make request with several ways – javascript, jquery ajax and php.
Code lesson
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>API Вконтакте</title>
</head>
<body>
<h1>API Вконтакте</h1>
<script type="text/javascript">
var script = document.createElement('SCRIPT');
script.src = "https://api.vk.com/method/users.get?user_ids=kamabzalov&fields=bdate&v=5.67&callback=callbackFunc";
document.getElementsByTagName("head")[0].appendChild(script);
function callbackFunc(result) {
console.log(result.response[0].first_name);
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$.ajax({
url: 'https://api.vk.com/method/users.get?user_ids=kamabzalov',
type: 'GET',
dataType: 'jsonp',
})
.done(function(data) {
console.log(data.response[0].last_name);
});
</script>
<?php
$res = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids=kamabzalov"), true);
echo $res['response'][0]['uid'];
?>
</body>
</html>
0 Comments