Skip to content

Commit 662569a

Browse files
authored
Merge pull request #8 from stife/codex/insights-im-facebook-manager-anzeigen
Add insights feature
2 parents 0488347 + b532512 commit 662569a

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Version 0.224.1
2121

2222
## Facebook Page Management
2323

24-
A simple web interface to manage the Facebook page **"Techno auf den Augen"** is included in the [`facebook-manager`](./facebook-manager) directory. It relies on Express and the built-in Node.js `fetch` API to list and create posts.
24+
A simple web interface to manage the Facebook page **"Techno auf den Augen"** is included in the [`facebook-manager`](./facebook-manager) directory. It relies on Express and the built-in Node.js `fetch` API to list and create posts and display basic page insights.

facebook-manager/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ This is a lightweight web interface for managing the Facebook page **"Techno auf
1818
```bash
1919
npm start
2020
```
21-
4. Open `http://localhost:3000` in your browser to manage posts.
21+
4. Open `http://localhost:3000` in your browser to manage posts and view insights.
2222

2323
## Features
2424

2525
- Anzeige der letzten Posts
2626
- Veröffentlichen neuer Beiträge
27+
- Anzeigen der wichtigsten Page Insights
2728
- Verstellbare API-Version über `API_VERSION`
2829

2930
Das Projekt basiert auf Node.js mit Express und nutzt den integrierten `fetch`-Support.

facebook-manager/public/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ <h1>Facebook Page Manager</h1>
1818
<h2>Recent Posts</h2>
1919
<ul id="posts"></ul>
2020

21+
<h2>Page Insights</h2>
22+
<ul id="insights"></ul>
23+
2124
<script>
2225
async function loadPosts() {
2326
const res = await fetch('/api/posts');
@@ -43,9 +46,26 @@ <h2>Recent Posts</h2>
4346
});
4447
document.getElementById('message').value = '';
4548
loadPosts();
49+
loadInsights();
4650
});
4751

52+
async function loadInsights() {
53+
const res = await fetch('/api/insights');
54+
const data = await res.json();
55+
const list = document.getElementById('insights');
56+
list.innerHTML = '';
57+
if (data.data) {
58+
data.data.forEach(metric => {
59+
const item = document.createElement('li');
60+
const value = metric.values && metric.values[0] ? metric.values[0].value : 'N/A';
61+
item.textContent = `${metric.title}: ${value}`;
62+
list.appendChild(item);
63+
});
64+
}
65+
}
66+
4867
loadPosts();
68+
loadInsights();
4969
</script>
5070
</body>
5171
</html>

facebook-manager/server.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ app.post('/api/posts', async (req, res) => {
4949
}
5050
});
5151

52+
app.get('/api/insights', async (req, res) => {
53+
const metrics = 'page_impressions,page_engaged_users';
54+
try {
55+
const response = await fetch(`${GRAPH_URL}/${PAGE_ID}/insights?metric=${metrics}&access_token=${ACCESS_TOKEN}`);
56+
const data = await response.json();
57+
if (!response.ok) {
58+
return res.status(response.status).json(data);
59+
}
60+
res.json(data);
61+
} catch (e) {
62+
res.status(500).json({ error: 'Failed to fetch insights', details: e.message });
63+
}
64+
});
65+
5266
const PORT = process.env.PORT || 3000;
5367
app.listen(PORT, () => {
5468
console.log(`Facebook manager running on port ${PORT}`);

0 commit comments

Comments
 (0)