¿cómo puedo obtener el ID del código de FacebookApiException $ e?

¿cómo puedo obtener el ID del código de FacebookApiException $e ?

Estoy usando Facebook para publicar. pero a veces no publica el contenido. Estoy usando estos códigos a continuación, y encuentro el ID del código de respuesta de error en array $e , pero todos están protegidos, ¿cómo puedo obtener el código?

 try{ $facebook->setAccessToken($access_token); $rs= $facebook->api('/me/feed','POST',$post_data); } catch (FacebookApiException $e) { print_r($e); } 

entonces obtengo la información de error:

 FacebookApiException Object ( [result:protected] => Array ( [error] => Array ( [message] => Invalid OAuth access token. [type] => OAuthException [code] => 190 // I need this code ) ) [message:protected] => Invalid OAuth access token. [string:private] => [code:protected] => 0 [file:protected] => D:\phpnow\htdocs\laji\facebook-php-sdk\base_facebook.php [line:protected] => 1267 [trace:private] => Array ( [0] => Array ( [file] => D:\phpnow\htdocs\laji\facebook-php-sdk\base_facebook.php [line] => 876 [function] => throwAPIException [class] => BaseFacebook [type] => -> [args] => Array ( [0] => Array ( [error] => Array ( [message] => Invalid OAuth access token. [type] => OAuthException [code] => 190 ) ) ) ) [1] => Array ( [file] => D:\phpnow\htdocs\laji\facebook-php-sdk\base_facebook.php [line] => 650 [function] => _graph [class] => BaseFacebook [type] => -> [args] => Array ( [0] => /me/feed [1] => POST [2] => Array ( [access_token] => 1CAACg13jYHp8BAP0QEOK8PwC7ZCMnSa1tAQclbRJpcNP1zQIBnB1to6etQ2wb8wiVcETDvT5dRZAUiNiZBFvt1RYgo5xUe1do4yeY5DxKIjjDBbElI8zZBBlz5yHRwigIcNYtyhHY9ZAtHL16ZAMPyo43wZANhGWE6o6EV7hXZBtxBEN24xTlGa7M [picture] => http://imgjy.com/FPB470/m/5236e26acc73a.jpg [link] => http://www.persunmall.com/persun/giveaway02.html?refer_id=1900 [name] => my all_prams link 7458 ) ) ) [2] => Array ( [file] => D:\phpnow\htdocs\laji\fb_post.php [line] => 98 [function] => api [class] => BaseFacebook [type] => -> [args] => Array ( [0] => Array ( [0] => Facebook Object ( [sharedSessionID:protected] => [appId:protected] => 176847305842335 [appSecret:protected] => f79311ddff5888a165d46159b06f4670 [user:protected] => [signedRequest:protected] => [state:protected] => [accessToken:protected] => [fileUploadSupport:protected] => [trustForwarded:protected] => ) [1] => _graph ) [1] => Array ( [0] => /me/feed [1] => POST [2] => Array ( [access_token] => 1CAACg13jYHp8BAP0QEOK8PwC7ZCMnSa1tAQclbRJpcNP1zQIBnB1to6etQ2wb8wiVcETDvT5dRZAUiNiZBFvt1RYgo5xUe1do4yeY5DxKIjjDBbElI8zZBBlz5yHRwigIcNYtyhHY9ZAtHL16ZAMPyo43wZANhGWE6o6EV7hXZBtxBEN24xTlGa7M [picture] => http://imgjy.com/FPB470/m/5236e26acc73a.jpg [link] => http://www.persunmall.com/persun/giveaway02.html?refer_id=1900 [name] => my all_prams link 7458 ) ) ) ) ) ) 

Sin haberlo probado, ¿no funcionaría?

 echo "Code: " . $e["error"]["code"]; 

Lo que entiendo en su consulta es que quiere código id es decir [código] => 190 vea aquí estamos usando la clase FacebookApiException que tiene el siguiente método

 **[0] => __construct [1] => getResult [2] => getType [3] => __toString [4] => getMessage [5] => getCode [6] => getFile [7] => getLine [8] => getTrace [9] => getPrevious [10] => getTraceAsString** so from your code try{ $facebook->setAccessToken($access_token); $rs= $facebook->api('/me/feed','POST',$post_data); } catch (FacebookApiException $e) { print_r($e); } as per your code you can do two thing 1. try{ $facebook->setAccessToken($access_token); $rs= $facebook->api('/me/feed','POST',$post_data); } catch (FacebookApiException $e) { echo $e->getCode(); //which is the 5th method of the class } or you can simply get all response like 2. try{ $facebook->setAccessToken($access_token); $rs= $facebook->api('/me/feed','POST',$post_data); } catch (FacebookApiException $e) { $result = $e->getResult(); //which is the 1st method of the class and provide you all response //so for getting the code only echo $result['error']['code']; } 

Espero que esto te ayudará

De acuerdo con el documento de Facebook. No estoy seguro si esta ayuda.

 $result = $e->getResult(); error_log(json_encode($result)); 

Por favor, siga: https://developers.facebook.com/docs/reference/php/exception-getResult