我想在symfony webapp上测试登录facebook,我已经创建了一个测试用户并为该用户请求了访问令牌,我想发送以下帖子请求:
public function setup()
{
$this->access_token = 'CAAL0aG1XXXXXX...';
$this->email = 'test....@tfbnw.net';
$this->uid = '105.......';
$this->formData =json_encode(
array(
'authResponse' => array(
'access_token' => $this->access_token,
'expiresIn' => 5418,
'userID' => $this->uid
),
'status' => 'connected'));
}
public function testFacebookConnection()
{
$client = static::createClient();
// Submit a raw JSON string in the request body
$client->request(
'POST',
$client->getContainer()->get('router')->generate('oauth_connect'),
array(),
array(),
array('CONTENT_TYPE' => 'application/json'),
'{ "service":"facebook","authentication" : "'. $this->formData.'"}'
);
die(var_dump($client->getResponse()->getContent()));
}
以及调用URI方法signuature
之下/**
* Calls a URI.
*
* @param string $method The request method
* @param string $uri The URI to fetch
* @param array $parameters The Request parameters
* @param array $files The files
* @param array $server The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
* @param string $content The raw body data
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
*
* @return Crawler
*/
public function request($method, $uri, array $parameters = array(), array $files = array(), array $server = array(), $content = null, $changeHistory = true)
{
答案 0 :(得分:6)
你应该在方法签名之后的第三个参数中使用post params:
$this->postData =
array(
'service' => 'facebook',
'authentication'=> $this->formData,
);
您可以按以下方式调用方法:
$client->request(
'POST',
$client->getContainer()->get('router')->generate('oauth_connect'),
$this->postData,
array(),
array('CONTENT_TYPE' => 'application/json')
);