Skip to content

nguyengiang160692/themartec_assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 

Repository files navigation

The Martec Assignment

Table of contents

  1. Introduction
  2. Stack and libraries
  3. Setup app
  4. Setup Social applications
    1. Facebook App
    2. Linkedin App
  5. TODO

Introduction

Basically, I have to create a web application that allows users to post articles to social networks (Facebook, Linkedin) and fetch likes, shares, comments count of that post.


Stack & libraries

Frontend

  • React
  • Redux
  • Redux-thunk (To make the process of asynchronous data flow easier)
  • React-router-dom
  • Axios
  • Material-UI

Backend

  • Laradock (docker for development, mostly I use for database mongodb in this assignment)
  • nvm (node version management) => require node version 18
  • Nodejs
  • Express
  • Mongoose
  • Joi (for validation input data)
  • Passport
  • Bcryptjs (Hash & salt)
  • Jsonwebtoken
  • mocha (for unit test)
  • supertest (for unit test)

Initial setup

cd frontend 
cp .env.example .env
yarn

cd backend
cp .env.example .env
yarn

Create new database using mongosh (Or you can create any way you want)

mongosh --authenticationDatabase <your_auth_source_db> -u <username> -p <password>

use '<your_auth_source_db>'

db.createUser({
  user: 'themartec_user',
  pwd: 'themartec_password',
  roles: [
    { role: 'dbOwner', db: 'themartec_db' },
  ],
})

Please set .env variable (/src/backend/.env)

  • MONGO_HOST=your_db_host
  • MONGO_PORT=27017
  • MONGO_SOURCE=themartec_db
  • MONGO_USERNAME=themartec_user
  • MONGO_PASSWORD=themartec_password

Setup Social applications

Facebook App

  1. Create new Facebook App (Type bussiness)
    • Create new product "Facebook Login For Bussiness"
      • Create Configuration for that product contains follow permissions
        • email
        • pages_manage_posts
        • pages_show_list
        • pages_read_engagement
        • pages_manage_engagement
        • pages_read_user_content
  2. After created app, set permissions, please set .env variable at /src/backend/.env
    • FACEBOOK_APP_ID=your_app_id
    • FACEBOOK_APP_SECRET=your_app_secret
  3. Set .env variable at /src/frontent/.env
    • REACT_APP_FACEBOOK_CLIENT_ID=your_app_id
    • REACT_APP_LOGIN_CONFIGURATION_ID=your_configuration_id
  4. Setup the page you want to post .env variable at /src/backend/.env
    • FACEBOOK_PAGE_ID=your_page_id
    • Need to get your page ID, please referer here

Linkedin App

  1. Create new Linkedin App & Company
    • Add products
      • Share on Linkedin
      • Sign In with Linkedin
    • Setup "Authorized redirect URLs for your app" for get access_token after successfully login by user
      • https://localhost:3005/api/auth/linkedin/callback (our backend side)
  2. After add products, set permissions, please set .env variable at /src/backend/.env
    • LINKEDIN_CLIENT_ID=app_client_id
    • LINKEDIN_CLIENT_SECRET=app_client_secret
    • LINKEDIN_REDIRECT_URI=https://localhost:3005/api/auth/linkedin/callback
  3. After add products, set permissions, please set .env variable at /src/backend/.env
    • REACT_APP_LINKEDIN_CLIENT_ID=app_client_id
    • REACT_APP_LINKEDIN_REDIRECT_URI=https://localhost:3005/api/auth/linkedin/callback

Mainly ideas (For facebook)

Sign in process

  • Because Facebook provide Javascript SDK to login, so Oauth2 sign-in proccess can be done by using Javascript SDK
  • Client side
    • After successfully login, I will get access_token (short-live), then I will send that token to backend
  • Backend side
    • On backend side, I will use access_token to get page_token
    • After get page_token, I will exchange page_token to long-live access_token (long-live)
    • Save both tokens to database to request later

Posting process

  • Use page_token to post thought this /${pageId}/feed endpoint, then save post_id to database to get like share comment later

Get like share comment

  • Use page_token to get like share comment thought this /${post_id}/?fields=likes.summary(true),shares.summary(true),comments.summary(true) endpoint every 15 minutes

Mainly ideas (For Linkedin)

  • Because Linkedin doesn't provide Javascript SDK to login, so Oauth2 sign-in proccess must be done by using backend, and receive access_token from Linkedin via assigned callback url on setup process

Posting proccess

  • Use access_token to post thought this /ugcPosts endpoint, then save post_id to database to get like share comment later

Get like share comment

  • Linkedin has endpoint to get like share comment count, but it require a submission for review your app before having permissions to do further, so we have to crawl HTML from this URL https://www.linkedin.com/embed/feed/update/${post_id} to get like share comment count, actually this link is not contains the share count, I only can get likes count and shares count

Thing to do

  • Write more unit-test for posting process
  • Facebook: an user can have many pages, so we need to add more page_id to database instead of using .env variable
  • Linkedin: find out way to get shares in post

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published