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.
- React
- Redux
- Redux-thunk (To make the process of asynchronous data flow easier)
- React-router-dom
- Axios
- Material-UI
- 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)
cd frontend
cp .env.example .env
yarn
cd backend
cp .env.example .env
yarn
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
-
Create new Facebook App (Type bussiness)
-
Create new product "Facebook Login For Bussiness"
-
Create Configuration for that product contains follow permissions
- pages_manage_posts
- pages_show_list
- pages_read_engagement
- pages_manage_engagement
- pages_read_user_content
-
Create Configuration for that product contains follow permissions
-
Create new product "Facebook Login For Bussiness"
-
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
-
Set .env variable at /src/frontent/.env
- REACT_APP_FACEBOOK_CLIENT_ID=your_app_id
- REACT_APP_LOGIN_CONFIGURATION_ID=your_configuration_id
-
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
-
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)
-
Add products
-
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
-
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
- 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
- Use page_token to post thought this
/${pageId}/feed
endpoint, then save post_id to database to get like share comment later
- 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
- 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
- Use access_token to post thought this
/ugcPosts
endpoint, then save post_id to database to get like share comment later
- 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
- 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