This repository has been archived by the owner on Nov 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.cfm
262 lines (246 loc) · 9.57 KB
/
index.cfm
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<cfdump var="#session#"/>
<cfdump var="#cookie#"/>
<cfdump var="#url#"/>
<!---
* Copyright 2010 Affinitiz, Inc.
* Copyright 2014 Ventego Creative Ltd
*
* Title: External website with Facebook Platform integration
* Initial Author: Benoit Hediard (hediard@affinitiz.com)
* Author: Kai Koenig (kai@ventego-creative.co.nz)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
--->
<cfscript>
import facebook.sdk.FacebookApp;
import facebook.sdk.FacebookGraphAPI;
// Replace this with your appId and secret
APP_ID = "";
SECRET_KEY = "";
SCOPE = "publish_stream,user_friends";
if (APP_ID is "" or SECRET_KEY is "") {
// App is not configured
facebookGraphAPI = new FacebookGraphAPI(apiVersion = "v2.0");
} else {
// Create facebookApp instance
facebookApp = new FacebookApp(appId=APP_ID, secretKey=SECRET_KEY, apiVersion = "v2.0");
//WriteDump(facebookApp);
// See if there is a user from a cookie or session
userId = facebookApp.getUserId();
//WriteDump(userId);
if (userId) {
//try {
WriteDump("b4 userAccessToken");
userAccessToken = facebookApp.getUserAccessToken();
extendedAccessToken = facebookApp.exchangeAccessToken(userAccessToken);
facebookGraphAPI = new FacebookGraphAPI(accessToken=extendedAccessToken, appId=APP_ID, apiVersion = "v2.0");
WriteDump("b4 userObject");
userObject = facebookGraphAPI.getObject(id=userId);
WriteDump("b4 userFriends");
userFriends = facebookGraphAPI.getConnections(id=userId, type='taggable_friends', limit=10);
authenticated = true;
//} catch (any exception) {
// Usually an invalid session (OAuthInvalidTokenException), for example if the user logged out from facebook.com
// userId = 0;
// facebookGraphAPI = new FacebookGraphAPI();
//}
} else {
facebookGraphAPI = new FacebookGraphAPI(apiVersion = "v2.0");
}
// Login or logout url will be needed depending on current user state.
if (userId) {
logoutUrl = facebookApp.getLogoutUrl();
} else {
parameters = {scope=SCOPE};
loginUrl = facebookApp.getLoginUrl(parameters);
}
}
// This call will in v2+ not work anymore, every graph API access needs a token now
try {
kai_and_ross_hometown = facebookGraphAPI.getObject(id='Wellington-New-Zealand');
} catch (any exception) {
kai_and_ross_hometown = "";
}
</cfscript>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>Facebook CFML SDK Examples (using API version 2)</title>
<link rel="stylesheet" type="text/css" href="website.css" />
</head>
<body>
<div class="menu">
<div class="content">
<div class="logo">
<img src="../../images/coldfusion-sdk-50x50.png" height="50" width="50" style="float:right" />
<span>Facebook CFML SDK (API version 2)</span>
</div>
<div class="clear"></div>
</div>
</div>
<div class="header">
<div class="content">
<h1>Facebook CFML SDK (API version 2) - Examples</h1>
Website with Facebook Platform integration
</div>
</div>
<div class="body washbody example">
<cfoutput>
<div id="status">
</div>
<div class="content">
<cfif APP_ID is "" or SECRET_KEY is "">
<div style="color:red">
<h4>Incorrect Facebook Application configuration</h4>
Your application is not yet configured, you must create an application on <a href="https://developers.facebook.com/apps">Facebook Developers</a>, in order to get your own app ID and a secret key.<br />
Replace <i>appId</i> and <i>secretKey</i> in <i>examples/website/index.cfm</i>.<br />
For more info, see SDK <a href="http://github.com/TheRealAgentK/facebook-cf-sdk/wiki/Usage">Usage</a> documentation.<br />
</div>
<br />
<cfelse>
<!--
We use the Facebook JavaScript SDK to provide a richer user experience. For more info,
look here: http://github.com/facebook/connect-js
-->
<div id="fb-root"></div>
<script>
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app and Facebook.
document.getElementById('status').innerHTML = 'loggedin ';
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
window.fbAsyncInit = function() {
FB.init({
appId : '#facebookApp.getAppId()#',
cookie : true,
oauth : true,
status : true,
xfbml : false,
version : 'v2.0'
});
//FB.getLoginStatus(function(response) {
// statusChangeCallback(response);
// });
// whenever the user logs in or logs out, we refresh the page
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
//console.log("received auth.login");
});
//FB.Event.subscribe('auth.logout', function(response) {
// window.location.reload();
//});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
//js.src = "//connect.facebook.net/en_US/sdk.js";
js.src="//connect.facebook.net/en_US/sdk/debug.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function login() {
FB.login(function(response) {
console.log('login');console.log(response);
if (response.authResponse) {
// User successfully authenticated in
// Page reload will be done by 'auth.login' event handler
} else {
// User cancelled login
}
}, {scope:'#SCOPE#'});
}
function logout() {
FB.getLoginStatus(function(response) {
console.log('logout');console.log(response);
if (response.authResponse) {
FB.logout(function(response) {
// User is now authenticated out
// Page reload will be done by 'auth.logout' event handler
});
} else {
window.location.reload();
}
});
}
</script>
<h2>Authentication</h2>
<cfif userId>
<div>
Log out via Facebook CFML SDK: <a href="#logoutUrl#">Logout</a>
</div>
<br />
<cfelse>
<div>
Log in via Facebook JavaScript SDK: <a href="javascript:login()">Login</a><br />
(<i>with Facebook ColdFusion SDK handling authorization code from cookie on reload</i>)
</div>
<br />
<!---<div>
Log in Facebook JavaScript SDK & XFBML: <fb:login-button scope="#SCOPE#"></fb:login-button><br />
(<i>with Facebook ColdFusion SDK handling authorization code from cookie on reload</i>)
</div> --->
<br />
</cfif>
<hr />
<h2>Your data</h2>
<cfif userId>
<h3>Your profile pic + name</h3>
<img src="https://graph.facebook.com/#userId#/picture">
#userObject.name#<br />
<br />
<h3>10 of your friends</h3>
<cfloop array="#userFriends#" index="friend">
<img src="#friend.picture.data.url#">
</cfloop><br />
<br />
<h3>Your info</h3>
<cfdump var="#userObject#" format="text">
<cfelse>
<strong><em>You are not Connected.</em></strong>
</cfif>
</cfif>
<hr />
<h2>Public data</h2>
<h3>Profile pic (this seems to be still working fine) + name (this will not work anymore when not logged in; see above in code, we need an access token for any graph API data request in v2+)</h3>
<img src="https://graph.facebook.com/Wellington-New-Zealand/picture">
<cfif isStruct(kai_and_ross_hometown)>#kai_and_ross_hometown.name#</cfif>
</div>
</cfoutput>
</div>
<div class="footer">
<div class="content">
<a href="http://github.com/TheRealAgentK/facebook-cf-sdk">Facebook CFML SDK</a>
<a href="http://www.apache.org/licenses/LICENSE-2.0">Licensed under the Apache License, Version 2.0</a><br />
</div>
</div>
</body>
</html>
<cfdump var="#session#"/>
<cfdump var="#cookie#"/>