facebook / facebook-php-business-sdk

PHP SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
833 stars 516 forks source link

$page->getLeadgenForms throws exception (#190) This method must be called with a Page Access Token #428

Closed KelseySheely closed 6 years ago

KelseySheely commented 6 years ago

The FacebookAds\Object\Page::getLeadgenForms() call now requires a Page Access Token rather than a User Access Token. If you try to pass that as the access_token as shown below

$page->getLeadgenForms([],["access_token"=>$pdata['access_token']])

it is overwritten by the session variable inside the FacebookAds\Api::prepareRequest() method.

$params_ref->enhance($this->getSession()->getRequestParameters());

This results in the exception (#190) This method must be called with a Page Access Token

If you don't add the access_token as a param, it still tries to use the User Access Token and throws the same exception.

KelseySheely commented 6 years ago

I still don't think this is ideal functionality especially since it is poorly documented, but it is possible to get around this by using a new FacebookAds\Api object for the calls you are making.

$original_api_instance = FacebookAds\Api::init($app_id, $app_secret, $user_access_token);
$page_api_instance = $original_api_instance->getCopyWithSession(new FacebookAds\Session($app_id, $app_secret, $page_access_token));
$page = new FacebookAds\Object\Page($page_id, null, $page_api_instance);
$leadgen_forms = $page->getLeadgenForms();
MercadoXL commented 6 years ago

573/5000 Hello I hope you can help me, I have exactly the same problem I do not understand what is referred to as "Page Access Token".

I have my advertising account and my face page, plus I have an app associated with my advertising account.

What I want is to obtain the data of my forms for potential cleintes.

The Token that I am using I get it from the configuration of my apps. in my products -> Marketing API -> in Get access token

ads_management ads_read manage_pages read_insights

If this does not work then what is the "Page Access Token"?

codytwinton commented 6 years ago

It seems like this issue has been open for more than a few months now. We have made many changes in the SDK since then, including releasing a new version. If you can repro your specific issue with the latest version of the SDK, please create a new issue or comment here with further details.