phpfacebookcurlfacebook-workplace

How to authenticate FB Workplace Account Management API in PHP?


How to authenticate FB Workplace Account Management API in PHP?

They haven't given much detail in the documentation but still here is the link for the documentation.(https://developers.facebook.com/docs/workplace/authentication/password)

And here is the code that I have written to get authentication so that I can get the list of users.Though I want to later add and delete them also and it can be done only through Account Management API and not the graph API.

Code:

$username='adnan@outsourcewebdev.com';

$password='P3YPFTluXc18'; 

//Its a trial acc username & pass. You can use to test it.

$URL='https://work-48884897.facebook.com/work/login';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$URL);

curl_setopt($ch, CURLOPT_TIMEOUT, 30); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

$result=curl_exec ($ch);

print_r($result); 

$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);  

echo $status_code; //get status code

curl_close ($ch);

Solution

  • The Account Management API, like the other Facebook APIs, requires an access token, not a username/password combination.

    https://developers.facebook.com/docs/workplace/account-management/api

    The Workplace Account Management API will only process requests that include a valid access token, which you must send with your API invocations as an authorization header.

    The docs you're referencing just explain that users can authenticate to the Facebook website in more than one way - either via username/password or an SSO.