Created
December 4, 2018 14:51
-
-
Save momenbasel/c997c07728d5264616e163e00790fe7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head><!--<script type="text/javascript" src="https://connect.facebook.net/en_US/sdk.js"> --></script></head> | |
<body> | |
// your platform code | |
<h1> my platform is amazing </h1> | |
<script> | |
window.fbAsyncInit = function() { | |
FB.init({ | |
appId : 'your-app-id', | |
autoLogAppEvents : true, | |
xfbml : true, | |
version : 'v3.2' | |
}); | |
}; | |
(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 = "https://connect.facebook.net/en_US/sdk.js"; | |
fjs.parentNode.insertBefore(js, fjs); | |
}(document, 'script', 'facebook-jssdk')); | |
// subscripping the app | |
function subscribeApp(page_id, page_access_token) { | |
FB.api( | |
'/'+ page_id + '/subscribed_apps', | |
'post', | |
{access_token: page_access_token, subscribed_fields: 'leadgen, leadgen_fat'}, | |
function(response) { | |
console.log('subscribed to page ', response); | |
}) | |
} | |
function myFacebookLogin() { | |
FB.login(function(response) | |
{ | |
console.log('loggedin', response); | |
FB.api('/me/accounts', function(response) | |
{ | |
// this response for the pages | |
console.log('successfully retrived pages', response); | |
var pages = response.data; | |
let length = pages.length; | |
const ul = document.getElementById('pages'); | |
// printing the name of pages the user have; | |
for(var i = 0; i < length ; i++ ) { | |
let page = pages[i]; | |
let li = document.createElement('li'); | |
let a = document.createElement('a'); | |
a.href = '#'; | |
a.onclick = subscribeApp.bind(this, page.id, page.access_token); | |
a.innerHTML = page.name; | |
li.appendChild(a); | |
ul.appendChild(li); | |
} | |
}) | |
},{scope: 'manage_pages,leads_retrieval'}); // in production it will need review for the page | |
}; | |
</script> | |
<button onclick="myFacebookLogin()">Login with Facebook </button> | |
<ul id="pages"> <ul> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment