So recently I have been trying to implement Facebook login to my nodejs app, I followed this articles which is short and simple https://medium.com/authpack/facebook-auth-with-node-js-c4bb90d03fc0, the only problem here is in user data I can't get the profile photo of user I tried adding a key profile_pic to scopes but it just doesn't work
below I'll share my code
Code for index.js this is my main server file where all the express and Facebook auth code lies , its easy and straight forward
const express = require("express");
const app = express();
const queryString = require("query-string");
const axios = require("axios");
app.set("view engine", "ejs");
const clientID=""
const clientSecret=""
const stringifiedParams = queryString.stringify({
client_id: clientID,
redirect_uri: "http://localhost:3000/auth/redirect",
scope: ["email", "user_friends"].join(","), // comma seperated string
response_type: "code",
auth_type: "rerequest",
display: "popup",
});
const facebookLoginUrl = `https://www.facebook.com/v4.0/dialog/oauth?${stringifiedParams}`;
app.get("/", (req, res) => {
res.render("login", { url: facebookLoginUrl });
});
app.get("/auth/redirect", async (req, res) => {
// here we are supposed to receive an code
// code is used to get an access token
// access token allows us to get data from facebook servers
const code = req.query.code;
try {
const { data } = await axios({
url: "https://graph.facebook.com/v4.0/oauth/access_token",
method: "get",
params: {
client_id: clientID,
client_secret: clientSecret,
redirect_uri: "http://localhost:3000/auth/redirect",
code,
},
});
console.log("CODE>>", code);
const access_token = data.access_token;
console.log("ACCESS_TOKEN>>", access_token);
const { data: info } = await axios({
url: "https://graph.facebook.com/me",
method: "get",
params: {
fields: ["id", "email", "first_name", "last_name"].join(","),
access_token: access_token,
},
});
console.log("we go the data back:>>>>", info);
res.render("home");
} catch (err) {
console.log("there was an err:", err.message);
}
});
app.listen(3000, () => {
console.log("server started on port 3000");
});
this is my code I think there must be some special key to add in scopes or fields section I don't know but I have tried a lot and its stressing me out , thanks guys