[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[fb-web] 10 Initialization

This page initialize this page loading the framework (at javascript level) in the page and test loading.

"Load Facebook SDK and test access to user"
| appId first script statusChangeCallback |
#{FB} notNil ifTrue: [
	^self print: 'Facebook framework already loaded in this page'
].

appId := '1934065846805962'.
statusChangeCallback := [:response|
	#{console} #log: response.
	response#status = 'connected'
	ifTrue:  [ FB current api: '/me' callback: [:me| UI8Inspector openOn: me ] ]
	ifFalse: [ self error: 'Connecting to the application' ]
].

#{window} basicAt: #fbAsyncInit put: [
	FB current init:
		#appId -> appId
		,(#autoLogAppEvents -> true)
		,(#xfbml -> true)
		,(#version -> 'v2.11').
	FB current appEvents logPageView.
].

(DOM document getElementById: #facebook-jssdk) notNil ifTrue: [
	script := DOM document createElement: #script.
	script	id: #facebook-jssdk;
		src: 'https://connect.facebook.net/en_US/sdk.js'.
	first := (DOM document getElementsByTagName: #script) first.
	(first @ #parentNode) #insertBefore: script json to: first json.
].

FB current getLoginStatus: statusChangeCallback


References