Facebook OAuthException: (#1)

不打扰是莪最后的温柔 提交于 2019-12-30 10:13:15

问题


I have a few applications which upload image to user profile. A few hours ago all applications were working fine but now when uploading 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'm using the following code to publish image.

$FILE = "images/$image";

$args = array('message' => 'My msg ');
$args['image'] = '@' . realpath($FILE);

$data = $facebook->api('/'.$uid.'/photos', 'post', $args);

Is it because of some policy change or some new feature?

I have all the permissions like upload is set to true and application takes permission to upload file.

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


回答1:


You need to verify if the user is logged in AND has the permissions to post on wall. We're going to do that with a TRY/CATCH with a call to the user.

$userId = $facebook -> getUser();

if ($userId) {
  try {
    // Proceed knowing you have a logged in user who's 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 logged in OR has authorized the app, you'll need to redirect him via header redirect or with a link.

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

That's the easiest way i've found.

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




回答2:


No, the error is caused by the system cannot get the image file. Facebook will not allow the empty image field appear in the api. So it return Fatal error: Uncaught OAuthException: (#1) --- although it does not relate to the OAuth and OAuthException.



来源:https://stackoverflow.com/questions/9124996/facebook-oauthexception-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!