Facebook OAuthException:(#1) [英] 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屋!