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 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题
  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接