forked from pgn420/facebookPlatform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.js
167 lines (143 loc) · 4.97 KB
/
menu.js
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
var gAppUrl = 'http://apps.facebook.com/platfom';
var gCoinsObjectURL = 'http://platformtest.herokuapp.com/coin.html';
function createSection(label, p_id) {
var para = $('<p>', {text: label}).appendTo('#stage');
$("<div>", {id: p_id, class: "a"}).appendTo(para);
return $('#'+p_id);
}
function createButton(container, label, func) {
var $button= $('<input/>').attr({ type: 'button', click:func,value:label, onclick:func+'()'});
$button.appendTo(container);
return $button;
}
function createMenu() {
var friendContainer = createSection('Friends', 'friend_container');
var selectFriends = document.createElement('select');
selectFriends.id = 'select_friends';
friendContainer.append(selectFriends);
var invitableFriendContainer = createSection('Invitable Friends', 'invitable_friend_container');
var selectInvitableFriends = document.createElement('select');
selectInvitableFriends.id = 'select_invitable_friends';
invitableFriendContainer.append(selectInvitableFriends);
createPayment();
createRequest();
createShare();
createAchievement();
var groupContainer = createSection('Game Group', 'group_container');
createButton(groupContainer, 'Create Group', 'createGroup');
var likeContainer = createSection('Like', 'like_container');
createButton(likeContainer, 'Like Object', 'likeObject');
var messengerContainer = createSection('Messenger', 'messenger_container');
createButton(messengerContainer, 'Send Dialog', 'sendDialog');
var a2uContainer = createSection('App to User Notification', 'a2u_container');
createButton(a2uContainer, 'Send A2U', 'sendA2U');
$('<input/>').attr({ type: 'text', id: 'access_token', value: 'access_token'}).appendTo(a2uContainer);
createAppEvents();
}
function buildProfile(uid) {
var profileContainer = document.createElement('div');
profileContainer.id = 'profile_container';
stage.appendChild(profileContainer);
FB.api('/me?fields=name', function(response) {
var profileName = document.createElement('div');
profileName.innerHTML = response.name;
profileName.id = 'profile_name';
profileContainer.appendChild(profileName);
var imageURL = 'https://graph.facebook.com/' + uid + '/picture?width=64&height=64';
var profileImage = document.createElement('img');
profileImage.setAttribute('src', imageURL);
profileImage.id = 'profile_image';
profileImage.setAttribute('height', '64px');
profileImage.setAttribute('width', '64px');
//profileContainer.appendChild(profileImage);
});
getFriends();
getInvitableFriends();
}
function likeObject() {
FB.api("me/og.likes", "post", {
object: "https://platformtest.herokuapp.com/cake1200.html",
}, function(response) { console.log(response) }
);
}
function createGroup() {
FB.ui({
method: 'game_group_create',
name: 'My Test Group',
description: 'A description for the test group',
privacy: 'OPEN',
},
function(response) {
if (response && response.id) {
alert("Group was created with id " + response.id);
} else {
alert('There was an error creating your group.');
}
}
);
}
function getPublishPermission() {
FB.login(function(response) {
if (response.authResponse) {
console.log('User granted publish_actions');
} else {
console.log('User did not grant publish_actions');
}
}, {
scope: 'publish_actions',
return_scopes: true
});
}
function getFriends() {
FB.api(
"/me/friends",
function (response) {
if (response && !response.error) {
var select = document.getElementById('select_friends');
for (var i = 0; i < response.data.length; i++) {
var option = document.createElement('option');
option.value = response.data[i].id;
option.innerHTML = response.data[i].name;
select.appendChild(option);
};
}
}
);
}
function getInvitableFriends() {
FB.api(
"/me/invitable_friends",
function (response) {
if (response && !response.error) {
var select = document.getElementById('select_invitable_friends');
for (var i = 0; i < response.data.length; i++) {
var option = document.createElement('option');
option.value = response.data[i].id;
option.innerHTML = response.data[i].name;
select.appendChild(option);
}
}
}
);
}
function getSelectedFriend() {
return document.getElementById('select_friends').value;
}
function getSelectedFriendInvitable() {
return document.getElementById('select_invitable_friends').value;
}
function sendDialog() {
var friend = getSelectedFriend();
FB.ui({
method: 'send',
link: gCoinsObjectURL,
redirect_uri: 'https://apps.facebook.com/testnewapipgn/',
to: friend
});
}
function sendA2U() {
$.get("a2u.php", {fbid: gPlayerFBID, access_token: document.getElementById("access_token").value}, fbCallback);
}
function fbCallback(response) {
console.log(response);
}