Facebook OAuthException: (#1)

萝らか妹 提交于 2019-12-01 06:21:41
William Fortin

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

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.

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