vendredi 27 mai 2016

Using Facebook SDK in WordPress plugin

I need to use Facebook Ads API in my WordPress plugin. The most classic way to use the Ads API instance is by setting it globally, like this:

Api::init($app_id, $app_secret, $access_token);

It's bad idea to use it this way from the plugin though, as it will be in conflict with other plugins using different Facebook app.

Instead, I can pass API instance to every object's constructor, like this:

$api = new FacebookAds\Api(
    new FacebookAds\Http\Client,
    new FacebookAds\Session($app_id, $app_secret, $access_token)
);

$ad = new FacebookAds\Object\Ad($id, $parent_id, $api);

But it's not very comfortable. Is there any kind of object factory in Facebook Ads SDK? Or maybe you guys have other ideas to make my plugin portable and bind Facebook app id, app secret and access token to my calls, instead of setting then globally?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire