|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Get Page Access Token</title> |
|
<style> |
|
body { |
|
font-family: Arial, sans-serif; |
|
text-align: center; |
|
margin-top: 50px; |
|
} |
|
#token { |
|
margin-top: 20px; |
|
font-size: 16px; |
|
color: green; |
|
} |
|
#error { |
|
margin-top: 20px; |
|
font-size: 16px; |
|
color: red; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<h1>Connect Your Facebook Page</h1> |
|
<p>Click the button below to connect your Facebook page and get the access token.</p> |
|
|
|
|
|
<a href="#" id="loginButton" style="display: inline-block; padding: 10px 20px; background-color: #1877F2; color: white; text-decoration: none; border-radius: 5px;"> |
|
Connect with Facebook |
|
</a> |
|
|
|
|
|
<div id="token"></div> |
|
<div id="error"></div> |
|
|
|
<script> |
|
|
|
const APP_ID = '1091493532996125'; |
|
const REDIRECT_URI = encodeURIComponent('https://dooratre-db-test.static.hf.space/index.html'); |
|
|
|
|
|
const oauthUrl = `https://www.facebook.com/v12.0/dialog/oauth?client_id=${APP_ID}&redirect_uri=${REDIRECT_URI}&scope=pages_manage_metadata,pages_read_engagement,pages_messaging,manage_pages&response_type=token`; |
|
|
|
|
|
document.getElementById('loginButton').href = oauthUrl; |
|
|
|
|
|
window.onload = () => { |
|
const hash = window.location.hash.substring(1); |
|
if (hash) { |
|
const params = new URLSearchParams(hash); |
|
const accessToken = params.get('access_token'); |
|
|
|
if (accessToken) { |
|
|
|
document.getElementById('token').innerText = `Access Token: ${accessToken}`; |
|
|
|
|
|
fetch(`https://graph.facebook.com/v12.0/me/accounts?access_token=${accessToken}`) |
|
.then(response => response.json()) |
|
.then(data => { |
|
if (data.data && data.data.length > 0) { |
|
const pages = data.data; |
|
let pageInfo = ''; |
|
pages.forEach(page => { |
|
pageInfo += `Page ID: ${page.id}, Page Token: ${page.access_token}\n`; |
|
}); |
|
document.getElementById('token').innerText += `\n\nPages:\n${pageInfo}`; |
|
} else { |
|
document.getElementById('error').innerText = 'No pages found for this user.'; |
|
} |
|
}) |
|
.catch(error => { |
|
document.getElementById('error').innerText = `Error fetching pages: ${error.message}`; |
|
}); |
|
} else { |
|
document.getElementById('error').innerText = 'Failed to retrieve access token.'; |
|
} |
|
} |
|
}; |
|
</script> |
|
</body> |
|
</html> |