Facebook API: How to get User's ad account ids?

919 Views Asked by At

So I'm trying to authenticate users via Facebook to access their ad accounts id (for ad management). I've checked that I have been granted permissions via the first ajax request.

Issue: Currently I'm using react-facebook-login package to authenticate users and the response i'm getting includes name, email, picture, userID

Attempt: I'm trying to figure out if there is a way to access user's ad account ids via given userID? Or is there a better endpoint I can use.

Current approach using react-facebook-login

import React from "react";
import FacebookLogin from "react-facebook-login";

class FacebookAuth extends React.Component {
  responseFacebook(response) {
    console.log("result --> ", response);

    fetch(
      "http://graph.facebook.com/yyy/permissions?access_token=xxx"
    ).then((res) => {
      console.log("permissions ==>", res);
    });
  }

  render() {
    return (
      <FacebookLogin
        appId="xxx"
        autoLoad={true}
        fields="name,email,picture, birthday"
        scope="email, ads_read"
        callback={this.responseFacebook}
      />
    );
  }
}

export default FacebookAuth;

Any ideas please?

1

There are 1 best solutions below

0
On

I suggest you to call the endpoint me/adaccounts:

{
  "data": [
    {
      "account_id": "xxx",
      "id": "act_xxx"
    },
    {
      "account_id": "yyy",
      "id": "act_yyy"
    },
 ]
}

That will return AdAccounts the user can access (See the doc for further fields)