Facebook OAuthException:(#1) [英] Facebook OAuthException: (#1)

查看:319
本文介绍了Facebook OAuthException:(#1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个应用程序将图像上传到用户配置文件。几个小时之前,所有的应用程序都正常工作,但是如果上传被请求,则会出现此错误。

 致命错误:未捕获OAuthException: (#1)第543行的应用程序/ fb-sdk / facebook.php中出现未知错误

我正在使用以下代码发布图像。

  $ FILE =images / $ image; 

$ args = array('message'=>'我的msg');
$ args ['image'] ='@'。真实路径($ FILE);

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

是因为某些政策更改或某些新功能吗?



我拥有所有权限,如upload被设置为true,应用程序需要上传文件的权限。



Ps:当应用程序第二次使用时,

解决方案

您需要验证用户是否登录,并具有在墙上发布的权限。我们将使用TRY / CATCH拨打电话给用户。

  $ userId = $ facebook  - > ;的getUser(); 

如果($ userId){
try {
//继续知道你有一个登录的用户被认证。
$ 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($ userId){
//然后你可以调用facebook api
$ data = $ facebook-> api('/'.$ uid。'/ photos','post',$ args);
// ... ...
}

这是最简单的方法我找到了。



编辑:堆栈上的这个问题帮助了我: Facebook PHP SDK上传照片


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.

解决方案

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

这篇关于Facebook OAuthException:(#1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆