简体   繁体   English

用facebook php sdk进行异常处理

[英]exception handling with the facebook php sdk

I have noticed that when uploading images to facebook album via created by my app using the php sdk for facebook, the sdk will occasionally throw an error. 我注意到,当使用我的应用程序使用php sdk for facebook通过我的应用程序创建的图像将图像上传到facebook相册时,sdk有时会引发错误。

I got an error from the sdk a few times in testing... however I put in a try catch... 我在测试中几次从sdk中收到错误...但是我尝试了一下...

    try{
        $picID = $this->facebook->api('/'.$this->aid.'/photos','post',$photo_details);
        var_dump($picID);
    }catch(Exception $e){
        echo('exception caught '.var_dump($e));
    }

and am trying to test it but by dumb luck the error will not occur again. 并正在尝试对其进行测试,但不幸的是,该错误不会再发生。 Can someone tell me if I can catch an exception this way? 有人可以告诉我是否可以这样捕获异常吗?

Thanks. 谢谢。

Try with: 尝试:

try {
    $picID = $this->facebook->api('/'.$this->aid.'/photos','post',$photo_details);
} catch(CurlException $e) {
    echo('exception caught '.$e->getMessage());
}

Don't really want to ressurect a question from 2012 but this has changed since then for anyone looking into it now. 真的不希望从2012年开始重新考虑一个问题,但是从那时起,对于现在正在调查此问题的任何人,这种情况都已改变。 For modern code using Facebook SDK 5.xx use the code... 对于使用Facebook SDK 5.xx的现代代码,请使用代码...

try {
    //Do something with the facebook code here
catch (FacebookSDKException $e) {
    //Handle the exception here
    //This will only catch exceptions thrown by the SDK but will cover them all, even ones thrown by libraries called by the SDK.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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