File size: 3,474 Bytes
336434a c0c4120 336434a c0c4120 336434a |
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 |
<!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>
<!-- Facebook Login Button -->
<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>
<!-- Display Access Token -->
<div id="token"></div>
<div id="error"></div>
<script>
// Facebook App ID
const APP_ID = '1091493532996125'; // Replace with your App ID
const REDIRECT_URI = encodeURIComponent('https://dooratre-db-test.static.hf.space/index.html'); // Replace with your redirect URI
// Generate Facebook OAuth URL
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`;
// Set the button's href to the OAuth URL
document.getElementById('loginButton').href = oauthUrl;
// Handle the response from Facebook
window.onload = () => {
const hash = window.location.hash.substring(1); // Get the hash from the URL
if (hash) {
const params = new URLSearchParams(hash);
const accessToken = params.get('access_token');
if (accessToken) {
// Display the access token
document.getElementById('token').innerText = `Access Token: ${accessToken}`;
// Fetch the user's pages
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> |