forked from tyaga/social-js-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
184 lines (163 loc) · 6.62 KB
/
example.html
File metadata and controls
184 lines (163 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>API test app</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js" type="text/javascript"></script>
<script src="./social-api.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
// создается глобальный враппер с заданным именем
new SocialApiWrapper(_get(document.location.search).api, App.wrapper_params, App.init);
});
var App = {
context: { },
wrapper_params: {
// имя глобальной переменной
wrapperName: 'wrap',
// ключи
mm_key: '1b6cf14981d250cb282adf96e33b4dde',
fb_id: '173107166050886',
// надо ли в конструкторе wrap-а сразу запустить авторесайз канваса
init_resize_canvas: false,
// какие данные надо проинициализировать сразу в конструкторе
init_user: true,
init_friends: true,
// песочница в одноклассниках
ok_sandbok: true,
// сводить к одному виду поля профиля
unify_profile_fields: true,
// оставлять остальные поля профиля
not_unified_fields: false,
// поля, которые надо выбрать
fields: ['id','birthdate','gender']
},
init: function(initedContext) {
// так как мы отключили авторесайз, врубаем его тут, например
wrap.initResizeCanvas();
// проинициализированные данные - в returnedContext
App.context = initedContext;
App.run();
},
run: function() {
log(wrap.getApiName(true), App.context);
jQuery("#test-methods").show('fast');
},
postWall: function() {
wrap.postWall({
id: App.context.friends.sort(function(){return Math.random()})[0].uid,
message: 'Странное сообщение на стену'
}, function() {
log('Message to the wall has posted', arguments);
}, function(event){
log(event);
});
},
makePayment: function() {
var params = {};
switch(wrap.getApiName()) {
case 'mm':
params = {
service_id: 1,
service_name: 'дьявольские вилы',
sms_price: 1,
other_price : 4000
};
break;
case 'vk':
params = {
votes: 1
};
break;
case 'ok':
params = {
name: 'test name',
description: 'test description',
items: [{
name: 'test',
price: 2,
code: 'coins'
}]
};
break;
}
wrap.makePayment(params, function(data) {
data = data || false;
log('Payment has done!');
data ? log(data) : null;
}, function() {
log('Error payment');
}, function(event){
log('Dialog closed', event);
});
},
testVK: function() {
// тестируем возможность прямого вызова методов
if (wrap.getApiName() == 'vk') {
wrap.raw.api('getGroups', {}, function(data){
log(data.response);
});
}
}
};
function log() {
for (var i in arguments) {
console.log(arguments[i]);
jQuery('#debug').html(JSON.stringify(arguments[i], null, ' '));
}
}
function _get(queryString) {
queryString = queryString.split("+").join(" ");
var params = {}, tokens;
var re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(queryString)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
return params;
}
</script>
</head>
<body>
<h4>Тестируем методы socialWrapper</h4>
<ul style="display:none;" id="test-methods">
<li><a href="javascript:void(0);" onclick="App.postWall()">Опубликовать на стену случайному другу</a></li>
<li><a href="javascript:void(0);" onclick="App.makePayment()">Заплатить денег</a></li>
<li><a href="javascript:void(0);" onclick="wrap.inviteFriends({install_message: 'install this great app'})">Пригласить друзей</a></li>
<li><a href="javascript:void(0);" onclick="App.testVK()">Только VK - getGroups</a></li>
</ul>
<pre>
<div id="debug">
</div>
</pre>
</body>
<!--
http://developers.facebook.com/docs/reference/dialogs/feed/
FB:
to: The ID or username of the profile that this story will be published to. If this is unspecified, it defaults to the the value of from.
message: The message to prefill the text field that the user will type in. To be compliant with Facebook Platform Policies, your application may only set this field if the user manually generated the content earlier in the workflow. Most applications should not set this.
link: The link attached to this post
picture: The URL of a picture attached to this post.
source: The URL of a media file (e.g., a SWF or video file) attached to this post. If both source and picture are specified, only source is used.
name: The name of the link attachment.
caption: The caption of the link (appears beneath the link name).
description: The description of the link (appears beneath the link caption).
properties: A JSON object of key/value pairs which will appear in the stream attachment beneath the description, with each property on its own line. Keys must be strings, and values can be either strings or JSON objects with the keys text and href.
http://api.mail.ru/docs/reference/js/guestbook-post/
http://api.mail.ru/docs/reference/js/stream-post/
MM:
Guestbook:
'uid': 123,
'title': 'заголовок записи, будет написан жирным шрифтом',
'text': 'основной текст вашей записи',
'img_url': 'http://exmaple.com/img.gif',
Stream:
'title': 'заголовок записи, будет написан жирным шрифтом',
'text': 'основной текст вашей записи',
'img_url': 'http://exmaple.com/img.gif',
http://vkontakte.ru/developers.php?o=-1&p=wall.post
VK:
owner_id: идентификатор пользователя, у которого должна быть опубликована запись. Если параметр не задан, то считается, что он равен идентификатору текущего пользователя.
message: текст сообщения (является обязательным, если не задан параметр attachment)
attachment: медиа-приложение к записи
-->
</html>