Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

zakariaelas
Copy link
Contributor

@zakariaelas zakariaelas commented Aug 1, 2020

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 🙏

@netlify
Copy link

netlify bot commented Aug 1, 2020

Deploy preview for geeksblabla ready!

Built with commit 48e6db6

https://deploy-preview-169--geeksblabla.netlify.app

Copy link
Contributor

@soub4i soub4i left a 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>
Copy link
Contributor

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}`
Copy link
Contributor

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}`
Copy link
Contributor

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
Copy link
Contributor

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")
Copy link
Contributor

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

@yjose yjose closed this Aug 2, 2023
soub4i added a commit to soub4i/geeksblabla.com that referenced this pull request Jan 21, 2024
yjose pushed a commit that referenced this pull request Jan 21, 2024
kaizendae pushed a commit to kaizendae/geeksblabla.com that referenced this pull request Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants