Facebook OAuthException: (#1)

后端 未结 2 456
误落风尘
误落风尘 2021-01-13 15:09

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

2条回答
  •  长情又很酷
    2021-01-13 15:15

    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

提交回复
热议问题