简体   繁体   English

Facebook php-sdk编写响应正文

[英]Facebook php-sdk writing in response body

I have a problem with the Facebook php-sdk-v4 . 我对Facebook php-sdk-v4有问题。
I have a back-end server using Symfony2 and a mobile application as a client. 我有一个使用Symfony2的后端服务器和一个移动应用程序作为客户端。
For authentication, I use the FOSOAuthServerBundle . 对于身份验证,我使用FOSOAuthServerBundle
I try to use Facebook Login in my mobile app. 我尝试在移动应用程序中使用Facebook登录。

To authenticate the user in the mobile app, I use the Android (or IOS) Facebook SDK and retrieve a facebook_access_token and the facebook_userID . 为了在移动应用程序中对用户进行身份验证,我使用Android(或IOS)Facebook SDK并检索了facebook_access_tokenfacebook_userID

I send them to the server where I check if the facebook_access_token is valid with this code where $socialToken is the facebook_access_token receive from the mobile app and $socialId is the facebook_userID receive from the mobile app : 我将它们发送到服务器,在该服务器上我使用以下代码检查facebook_access_token是否有效,其中$socialToken是从移动应用程序接收的facebook_access_token ,而$socialId是从移动应用程序接收的facebook_userID

$facebook = new Facebook(array(
    'app_id'  => self::FACEBOOK_APP_ID,
    'app_secret' => self::FACEBOOK_SECRET,
    'default_graph_version' => 'v2.4',
    'default_access_token' => $socialToken
));
$result = $facebook->get('/me');
$this->socialDetails = $result->getGraphUser();
if ($this->socialDetails->getId() != $socialId) {
    $this->logger->info("checkFacebookAccessToken : Token is NOT valid");
    return false;
}
$this->logger->info("checkFacebookAccessToken : Token is valid");
return true;

This code is working fine. 这段代码工作正常。 Once the token validated, I forward the request to the FOSOAuthServerController to generate an access token and return this access_token to the mobile app with : 令牌通过验证后,我将请求转发到FOSOAuthServerController生成访问令牌,然后使用以下命令将此access_token返回到移动应用程序:

return $response = $this->get('fos_oauth_server.controller.token')->tokenAction($request);

This code is working too. 该代码也起作用。 But the problem is that the response body send to the mobile app is the following : 但是问题在于,发送到移动应用程序的响应正文如下:

object(Facebook\GraphNodes\GraphUser)#616 (1) {
     ["items":protected]=>
     array(2) {
         ["name"]=>
             string(16) "John Doe"
         ["id"]=>
             string(15) "123456789012345"
     }
}
{
    "access_token":"myAccessToken",
    "expires_in":3600,
    "token_type":"bearer",
    "scope":null,
    "refresh_token":"myRefreshToken"
}

instead of : 代替 :

{
    "access_token":"myAccessToken",
    "expires_in":3600,
    "token_type":"bearer",
    "scope":null,
    "refresh_token":"myRefreshToken"
}

It seems that Symfony appends the 2 responses body . 似乎Symfony 追加了2个响应正文 But when I log the response return by the FOSOAuthServerBundle controller it only displays the second response. 但是,当我记录由FOSOAuthServerBundle控制器返回的响应时,它仅显示第二个响应。

Maybe the Facebook php-sdk writes directly in the response body. 也许Facebook php-sdk直接写在响应正文中。 Is there a way to delete the content of the response body before forwarding the request to the FOSOAuthServerBundle controller ? 在将请求转发到FOSOAuthServerBundle控制器之前,是否可以删除响应主体的内容?

It looks like you forgot a var_dump($this->socialDetails); 好像您忘记了var_dump($this->socialDetails); somewhere in your code. 您代码中的某个地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM