I have the problem that users can use our system to request reports of their ads on facebook.
These are the functions I use in the frontend (React):
export function initFacebookSdk() {
return new Promise(resolve => {
// wait for facebook sdk to initialize before starting the react app
window.fbAsyncInit = function () {
window.FB.init({
appId: 'app-id',
cookie: true,
xfbml: true,
version: 'v14.0'
});
resolve()
};
});
}
export const FbLogin = () => {
loadFacebookSDK(document, "script", "facebook-jssdk")
initFacebookSdk()
return new Promise( resolve => {
window.FB.login(response => {
if (response.authResponse) {
resolve(response);
} else {
resolve(response);
}
}, {scope: 'ads_management,ads_read'});
})
}
And so I call the function
const response = await FbLogin();
I send the token to the backend and this is how it uses the route:
try {
const { data: accountsInfo } = await axios({
url: `https://graph.facebook.com/v${FB_GRAPH_API_VERSION}/me/adaccounts?access_token=${accessToken}&pretty=1&limit=100`,
method: 'GET',
});
res.status(200).json({success: true, accountsInfo})
} catch (err) {
console.log(err);
res.status(500).json({success: false})
}
And this is the error that I get when trying to use the user token:
'OAuth "Facebook Platform" "invalid_request" "(#100) You must provide an app access token, or a user access token that is an owner or developer of the app"'
Does anyone know why this is happening to me? help 🙁