我知道这个问题已经讨论过但是我仍然无法找到解决方案。
我将HWIOAuth Bundle与FOSUserBundle用于我的用户和社交关系。
#app/config.yml
#HWIOAuthBundle
hwi_oauth:
firewall_name: main
resource_owners:
facebook:
type: facebook
client_id: %oauth.facebook.id%
client_secret: %oauth.facebook.secret%
scope: "email"
options:
display: popup
infos_url: "https://graph.facebook.com/me?fields=id,name,email,picture.type(square)"
paths:
email: email
profilepicture: picture.data.url
http_client:
verify_peer: false
如何在我的Twig文件中集成“profilepicture:picture.data.url”?
<li class="user-header">
<img src="{{ asset('theme/AdminLTE/dist/img/user2-160x160.jpg') }}" class="img-circle" alt="User Image" />
<p>
{{ app.user.username }}
</p>
</li>
非常感谢,我不明白如何使用此参数“profilepicture:picture.data.url”来获取带有HWIOAuthBundle的facebook个人资料图片。
答案 0 :(得分:0)
您可以在loadUserByOAuthUserResponse(UserResponseInterface $ response)中收到需求详情:
/* @var $response \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface */
var_dump(
$response->getEmail(),
$response->getProfilePicture()
);
答案 1 :(得分:0)
我解决了这个问题,在我的实体中添加了一个字段:
//Acme/UserBundle/Entity/User.php
/**
* @var string
*
* @ORM\Column(name="profile_picture", type="string", length=250, nullable=true)
*
*/
protected $profilePicture;
并像这样修改UserProvider.php:
//Acme/UserBundle/OAuth/UserProvider.php
protected function updateUserByOAuthUserResponse(User $user, UserResponseInterface $response)
{
$providerName = $response->getResourceOwner()->getName();
$providerNameSetter = 'set'.ucfirst($providerName).'Id';
$user->$providerNameSetter($response->getUsername());
$user->setProfilePicture($response->getProfilePicture());
if(!$user->getPassword()) {
// generate unique token
$secret = md5(uniqid(rand(), true));
$user->setPassword($secret);
}
return $user;
}