Facebook OAuthException: (# 1)

I have several applications that upload an image to a user profile. A few hours ago, all the applications worked fine, but now when the download is requested, it gives this error

Fatal error: Uncaught OAuthException: (#1) An unknown error occurred thrown in applications/fb-sdk/facebook.php on line 543 

I am using the following code to post an image.

 $FILE = "images/$image"; $args = array('message' => 'My msg '); $args['image'] = '@' . realpath($FILE); $data = $facebook->api('/'.$uid.'/photos', 'post', $args); 

Is it due to a policy change or some new feature?

I have all permissions, such as upload, set to true, and the application gets permission to upload the file.

Ps: when the application is used the 2nd time, it works fine.

+4
source share
2 answers

You need to check if the user is logged in and has permission to publish on the wall. We are going to do this using TRY / CATCH with a call to the user.

 $userId = $facebook -> getUser(); if ($userId) { try { // Proceed knowing you have a logged in user who authenticated. $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { $userId = NULL; error_log($e); } } $app_permissions = array( 'scope' => 'publish_stream' ); $logoutUrl = $facebook->getLogoutUrl(); $loginUrl = $facebook->getLoginUrl($app_permissions); 

If the user is not registered in OR, he has allowed the application, you need to redirect it through the header redirect or link.

 if ($userId){ //Then you can call the facebook api $data = $facebook->api('/'.$uid.'/photos', 'post', $args); //... ... } 

This is the easiest way I've found.

EDIT: This question on the stack helped me: Facebook PHP SDK Upload Photos

+2
source

No, the error is caused by the fact that the system cannot receive the image file. Facebook will not allow the empty image field in the api. Therefore, it returns Fatal error: Uncaught OAuthException: (# 1) --- although this does not apply to OAuth and OAuthException.

+1
source

Source: https://habr.com/ru/post/1394553/


All Articles