duankuan5319 2015-03-21 01:46
浏览 125
已采纳

FaceBookRequest-> execute()使我的ajax调用返回状态为500

I'm trying to make a php script which receives an ajax call from a Facebook application to check if the id sent by the user is his own. I get the user id and access token in the next piece of code. The function validateMe() puts the id, the letter z as a separator and the access token together, then makes an ajax call

FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
        monLogin.uid=response.authResponse.userID;
        monLogin.token=response.authResponse.accessToken;
        validateMe();
    } 
}

the php script which receives the ajax call comes next. It returns to the ajax call with status 500 when the line $response=request->execute(); is not commented. When I stop the code before this line by commenting it, it returns to the ajax call with status 200. So, I believe there is something that makes this line not working as expected. I tried changing the name $faceb to $session as in some examples, but that's not it. Using the Facebook = new Facebook(array) object instead of the method setDefaultApplication doesn't do the trick either because the Facebook object is deprecated.

<?php
session_start();
include 'vendor/autoload.php';
use Facebook\FacebookSession;
use Facebook\GraphObject;
use Facebook\GraphUser;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;

if (isset($GLOBALS['HTTP_RAW_POST_DATA'])){
    $appid='123456';  //not the true appid
    $psswd='123456abcdef';  //not the true password
    FacebookSession::setDefaultApplication($appid, $psswd);
    $infosJoueur = $GLOBALS['HTTP_RAW_POST_DATA'];
    $arrayData = explode('z', $infosJoueur, 2);

    // arrayData[1] is the accessToken from the javascript
    $session = new FacebookSession($arrayData[1]);
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();

    /*$graph = $response->getGraphObject(GraphUser::className());
    $id = $graph->getId();
    if (($arryData[0] = $id)) {
        echo 'yes';
        $_SESSION['uid']=$id;
    }
    else {echo 'no';}*/
}
?>

as proposed in the comments, i checked the logs of the server and found that the mbstring method didn't exist because I had to add it in the composer.json file. in the require, i added "ext-mbstring": "*". I still get an error 500 with a different log:

PHP Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message 'The access token could not be decrypted'

  • 写回答

1条回答 默认 最新

  • douzhuijing4911 2015-03-21 04:53
    关注

    thank you for pointing that more details on the problem could be in the server logs: mb_substr is not there by default for php, we have to tell php were to find it.

    Call to undefined function Facebook\HttpClients\mb_substr() in /app/vendor/facebook/php-sdk-v4/src/Facebook/HttpClients/FacebookCurlHttpClient.‌​php on line 254

    The answer can be found there Facebook PHP SDK error mb_substr

    (then i had a few bugs that i added while tweaking the code in search of a solution like removing the 2 in the explode)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵