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)

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

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路