Intro to API VKontakte
In the next two or three lessons we’ll discuss basics of api VKontakte using ajax knowledges, In this lesson we’ll consider api app creating and installing widgets for sites
URL of API VKontakte is https://vk.com/dev. You need Web section. Next you need create app in my applications section.
After creating app we’ll install some widgets from https://vk.com/dev/widgets_for_sites section.
Widgets install very easy – you only need copy and paste code (maybe you want to configure some settings before installing widget), and widget will be work in your site.
Especially you need to notice to
Widgets install very easy – you only need copy and paste code (maybe you want to configure some settings before installing widget), and widget will be work in your site.
Especially you need to notice to
In this lesson we’ll consider simple example, but I recommend you to learn documentation of this widget in details.
Code lesson (widgets)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://vk.com/js/api/openapi.js?146" type="text/javascript"></script>
<script type="text/javascript" src="https://vk.com/js/api/share.js?95" charset="windows-1251"></script>
</head>
<body>
<script type="text/javascript">
VK.init({apiId: 6141213});
</script>
<!-- Put this div tag to the place, where Auth block will be -->
<div id="vk_auth"></div>
<script type="text/javascript">
VK.Widgets.Auth("vk_auth", {authUrl: '/hello.php'});
</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>
<!-- VK Widget -->
<div id="vk_community_messages"></div>
<script type="text/javascript">
VK.Widgets.CommunityMessages("vk_community_messages", 85705787, {expanded: "1",tooltipButtonText: "Есть вопрос?"});
</script>
<!-- Put this script tag to the place, where the Share button will be -->
<script type="text/javascript"><!--
document.write(VK.Share.button(false,{type: "round", text: "Сохранить"}));
--></script>
<!-- Put this div tag to the place, where the Like block will be -->
<div id="vk_like"></div>
<script type="text/javascript">
VK.Widgets.Like("vk_like", {type: "button"});
</script>
</body>
</html>
Code lesson (VK API auth)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?php
$hash = $_GET['hash'];
if($hash == md5('614121390759251MXvRdponYG8lktKIhh9I')) { ?>
<h1>Hello</h1>
<?php } else { ?>
<h1>Ошибка входа</h1>
<?php } ?>
</body>
</html>
0 Comments