简体   繁体   中英

facebook marketing api exception handling

I am using Facebook marketing/graph api v2.8. I have read exception handling from here https://developers.facebook.com/docs/php/FacebookRequestException/5.0.0 , I am using following code for exception handling.

try {

} catch (Facebook\Exceptions\FacebookResponseException $e) {
      return $e->getMessage();        
    } catch (Facebook\Exceptions\FacebookAuthenticationException $e) {
      return $e->getMessage();        
    } catch (Facebook\Exceptions\FacebookAuthorizationException $e) {
      return $e->getMessage();        
    } catch (Facebook\Exceptions\FacebookClientException $e) {
      return $e->getMessage();        
    } catch (Facebook\Exceptions\FacebookOtherException $e) {
      return $e->getMessage();        
    } catch (Facebook\Exceptions\FacebookServerException $e) {
      return $e->getMessage();       
    } catch (Facebook\Exceptions\FacebookThrottleException $e) {
      return $e->getMessage();        
    } catch(Facebook\Exceptions\FacebookSDKException $e) {        
      return $e->getMessage();                
    } catch(Exception $e) {
        return "error";
    }

But still I am getting following AuthorizationException

Uncaught exception, operation failedexception 'FacebookAds\\Http\\Exception\\AuthorizationException' with message '(#2663) Terms of service has not been accepted. To accept, go to https://www.facebook.com/customaudiences/app/tos?act=

I tried to include

use Facebook\Exceptions\FacebookResponseException;
use Facebook\Exceptions\FacebookAuthenticationException;
use Facebook\Exceptions\FacebookAuthorizationException;
use Facebook\Exceptions\FacebookClientException;
use Facebook\Exceptions\FacebookOtherException;
use Facebook\Exceptions\FacebookServerException;
use Facebook\Exceptions\FacebookThrottleException;
use Facebook\Exceptions\FacebookSDKException;

But still no gain.

Actually I want to cover maximum errors so that can show to users in a user friendly way so anyone can tell what I am missing or what is the perfect way for exception handling in facebook marketing api?

The reason is you are mixing two SDKs in your code. One is the general Facebook SDK and another is Facebook Marketing API SDK ( https://github.com/facebook/facebook-php-ads-sdk )

Those exceptions start with Facebook/ are from Facebook SDK and those starting from FacebookAds are from Marketing API SDK.

I completely understand this is not ideal for developers. But you can also see the reason we have a separate SDK for Marketing API is because our Ads data model are too complicated and we need a more strong typed SDK to help developer to do the integration. And due to lots of reason it cannot be build on top of the general Facebook SDK.

So for now, you will have too look at both documentations for Marketing API/SDK and the general Facebook SDK. We will get your feedback and see if we have opportunity to improve it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM