我正在尝试将facebook连接集成到我们的网站(Symfony)中,为此我们使用FOSFacebookBundle。
我能够做到这一点,并获得我的facebook id、first_name和last_name,并将它们插入到我们的fos_user列中的新用户中。
关于用户档案图片,我一直收到一个例外:
An exception occurred while executing 'INSERT INTO fos_user (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, locked, expired, expires_at, confirmation_token, password_requested_at, roles, credentials_expired, credentials_expire_at, nom, prenom, solde, path, sexe, date_Naissance, facebookId, photo) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["1223800560964254", "1223800560964254", "******@gmail.com", "*********@gmail.com", 1, "", "", null, 0, 0, null, null, null, "a:1:{i:0;s:12:"ROLE_PORTEUR";}", 0, null, "Mohamed", "Elloumi", null, null, null, null, "1223800560964254", {"data":{"is_silhouette":false,"url":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/v/t1.0-1/c85.25.315.315/s50x50/580232_622196307791352_1230572455_n.jpg?oh=17c02ae42bb18d3ddbe3cfdf04239049&oe=57AC3250&__gda__=1474408706_227fd87692ead8189d332a4898571e62"}}]:
Notice: Array to string conversion
我认为这是因为我试图将完整的图片api Graph响应添加到blob列中:
{
"picture": {
"data": {
"is_silhouette": false,
"url": "https://fbcdn-profile-a.akamaihd.net/****"
}
},
"id": "792374454106869"
}
我想我只需要在我的blob列中插入这一行:
"url": "https://fbcdn-profile-a.akamaihd.net/****"
我使用这个php函数插入到fos_user表中:
public function setFBData($fbdata) // C'est dans cette méthode que vous ajouterez vos informations
{
if (isset($fbdata['id'])) {
$this->setFacebookId($fbdata['id']);
$this->addRole('ROLE_PORTEUR');
}
if (isset($fbdata['first_name'])) {
$this->setNom($fbdata['first_name']);
}
if (isset($fbdata['last_name'])) {
$this->setPrenom($fbdata['last_name']);
}
if (isset($fbdata['email'])) {
$this->setEmail($fbdata['email']);
}
if (isset($fbdata['picture'])) {
$this->setPhoto($fbdata['picture']);
}
}
为什么是blob?varchar(255)应该足以作为url。你应该能够访问图片数组中的url,如下所示:
$fbdata['picture']['data']['url']