-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add views count for episodes #169
Conversation
Deploy preview for geeksblabla ready! Built with commit 48e6db6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for a few tiny fixes
@@ -17,7 +17,7 @@ export default ({ title, date, slug, duration, active }) => ( | |||
<div> | |||
<h2>{title}</h2> | |||
<p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small padding will be nice here
@@ -76,7 +81,28 @@ exports.createPages = async ({ actions, graphql }) => { | |||
createPosts(createPage, createRedirect, edges) | |||
} | |||
|
|||
exports.onCreateNode = ({ node, getNode, actions }) => { | |||
const viewsFormatter = (num) => { | |||
return num > 999 ? `${(num / 1000).toFixed(1)}k` : `${num}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Intl.NumberFormat
for a generic logic for number formating (please mention me if you need a hand)
|
||
const accessToken = `${process.env.FB_PAGE_ACCESS_TOKEN}` | ||
const data = await fetch( | ||
`https://graph.facebook.com/v7.0/${videoId}/video_insights?metric=total_video_views&access_token=${accessToken}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have URL as a const
at the top of file gives more readability
|
||
// For episodes created in the DevC group, return a random number from 2k to 4k | ||
if (data.error) { | ||
return Math.floor(Math.random() * (4000 - 2000 + 1)) + 2000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning N/A
is more relevant to me
@@ -155,6 +181,15 @@ exports.onCreateNode = ({ node, getNode, actions }) => { | |||
node, | |||
value: node.frontmatter.video || "", | |||
}) | |||
|
|||
const views = await getVideoViewsCount("738019970309937") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the id here is hardcoded
As discussed in #137, this implements adding a views count for episodes by querying the FB Graph API.
Unfortunately, Facebook does not support getting the number of views for videos created on Facebook groups, only for Facebook pages (more on this here).
@yjose I am creating this pull request just so you can see if I need to change anything while waiting for Facebook to review the app.
Thanks and please let me know what you think 🙏