Search code examples
javascriptfacebookfacebook-graph-apiaxiosfacebook-insights

OAuth "Facebook Platform" "access_denied" "Cannot call API for app


Background

My app is utilizing Instagram insight data and therefore requires the user to login via Facebook to grant the needed permissions such as instagram_manage_insights, public_profile, etc. When validating the permissions by using the access token from login, I receive an unexpected error for SOME users, not all users which drives me crazy.

Problem

// Request granted permissions
const url = "https://graph.facebook.com/v7.0/me/permissions?access_token=XXXXX";
const response = await axios.get(url)

//Expected result
{
 "data": [
  {
     "permission": "email",
     "status": "granted"
  },
  {
     "permission": "pages_show_list",
     "status": "granted"
  },
  {
     "permission": "instagram_basic",
     "status": "granted"
  },
  {
     "permission": "instagram_manage_insights",
     "status": "granted"
  },
  {
     "permission": "public_profile",
     "status": "granted"
  }
 ]
}

//Response
404 Bad Request
'OAuth "Facebook Platform" "access_denied" "Cannot call API for app XXXXXX on behalf of user XXXXXX"'

When I validate the access token in Facebook developer console access token debugger (https://developers.facebook.com/tools/debug/accesstoken) there is no problem, no different from the working users.

When I run a non working user in the web browser (https://graph.facebook.com/v7.0/me/permissions?access_token=XXXX) everything works fine and I get the expected result.

I assume the problem is caused by axios but how and why the inconsistency?


Solution

  • Solved

    So the solution turned out to be the "Country Restricted" switch in Settings > Advanced > App Restrictions. Switching it off solved my problem. Not very clear...

    Screenshot