API VKontakte. Get access token

Home » Tutorials » JavaScript » API VKontakte. Get access token
In this lesson we will finish introductory series of lessons with api VKontakte work. We’ll consider necessity and getting access token procedure.
While api making requests some methods return only public data. For example, users.get method returns only first_name, last_name and id. To get other fields, you must pass access token in request. How to get it you may rad this article.

Code lesson

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>API Вконтакте</title>
</head>
<body>


	<h1>API Вконтакте</h1>


	<!-- Put this script tag to the <head> of your page -->
<script type="text/javascript" src="//vk.com/js/api/openapi.js?146"></script>

<script type="text/javascript">
  VK.init({apiId: 6148618, onlyWidgets: true});
</script>

<!-- Put this div tag to the place, where the Comments block will be -->
<div id="vk_comments"></div>
<script type="text/javascript">
VK.Widgets.Comments("vk_comments", {limit: 10, attach: "*"});
</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/widgets.getComments?widget_api_id=6148618&url=http://codetogether.ru/',
			type: 'GET',
			dataType: 'jsonp',
		})
		.done(function(data) {
			console.log(data.response.posts[0].text);
		});
	</script>


	<script>
		$.ajax({
			url: 'https://api.vk.com/method/users.get?user_ids=kamabzalov&fields=photo_id,verified,sex,bdate,city,country,home_town,has_photo,photo_50,photo_100,photo_200_orig,photo_200,photo_400_orig,photo_max,photo_max_orig,online,domain,has_mobile,contacts,site,education,universities,schools,status,last_seen,followers_count,common_count,occupation,nickname,relatives,relation,personal,connections,exports,wall_comments,activities,interests,music,movies,tv,books,games,about,quotes,can_post,can_see_all_posts,can_see_audio,can_write_private_message,can_send_friend_request,is_favorite,is_hidden_from_feed,timezone,screen_name,maiden_name,crop_photo,is_friend,friend_status,career,military,blacklisted,blacklisted_by_me&v=5.67&access_token=6d96c35755e775d83b48efcb996d39f875e09a0166895b6f34d6f9332ff8b853be550954b7b60fd8ecd81',
			type: 'GET',
			dataType: 'jsonp',
		})
		.done(function(data) {
			console.log(data);
		});
	</script>

</body>
</html>

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Pin It on Pinterest

Share This