-
Notifications
You must be signed in to change notification settings - Fork 38
Save user information in database using FOSTwitterBundle #57
Comments
Read the error message:
You're -use FOS\UserBundle\Entity\UserManager;
+use FOS\UserBundle\Doctrine\UserManager; |
Thanks but no I get this error : _ErrorException: Catchable Fatal Error: Argument 4 passed to Skeleton\PanelBundle\Security\User\Provider\TwitterUserProvider::_construct() must be an instance of Symfony\Component\HttpFoundation\Session, instance of Symfony\Component\HttpFoundation\Session\Session given, called in /var/www/skeleton/app/cache/dev/appDevDebugProjectContainer.php on line 1678 and defined in /var/www/skeleton/src/Skeleton/PanelBundle/Security/User/Provider/TwitterUserProvider.php line 34 and here is TwitterUserProvider : <?php
namespace Skeleton\PanelBundle\Security\User\Provider;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\HttpFoundation\Session;
use \TwitterOAuth;
use FOS\UserBundle\Doctrine\UserManager;
use Symfony\Component\Validator\Validator;
class TwitterUserProvider implements UserProviderInterface
{
/**
* @var \Twitter
*/
protected $twitter_oauth;
protected $userManager;
protected $validator;
protected $session;
public function __construct(TwitterOAuth $twitter_oauth, UserManager $userManager,Validator $validator, Session $session)
{
$this->twitter_oauth = $twitter_oauth;
$this->userManager = $userManager;
$this->validator = $validator;
$this->session = $session;
}
public function supportsClass($class)
{
return $this->userManager->supportsClass($class);
}
public function findUserByTwitterId($twitterID)
{
return $this->userManager->findUserBy(array('twitterID' => $twitterID));
}
public function loadUserByUsername($username)
{
$user = $this->findUserByTwitterId($username);
$this->twitter_oauth->setOAuthToken($this->session->get('access_token'), $this->session->get('access_token_secret'));
try {
$info = $this->twitter_oauth->get('account/verify_credentials');
} catch (Exception $e) {
$info = null;
}
if (!empty($info)) {
if (empty($user)) {
$user = $this->userManager->createUser();
$user->setEnabled(true);
$user->setPassword('');
$user->setAlgorithm('');
}
$username = $info->screen_name;
$user->setTwitterID($info->id);
$user->setTwitterUsername($username);
$user->setEmail('');
$user->setFirstname($info->name);
$this->userManager->updateUser($user);
}
if (empty($user)) {
throw new UsernameNotFoundException('The user is not authenticated on twitter');
}
return $user;
}
public function refreshUser(UserInterface $user)
{
if (!$this->supportsClass(get_class($user)) || !$user->getTwitterID()) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
}
return $this->loadUserByUsername($user->getTwitterID());
}
} |
Please read the error message! PHP says you have the wrong use statement. |
Yes i'm using symfony 2.2.1 the last one... |
Here is the problem I guess,this bundle works just with symfony 2.0? |
No, your problem is, that you didn't read the Changelog. The session component has been refactored in symfony 2.1. The new namespace is Can you close this issue, its not related to the bundle. |
Ok I don't have any error now,but the last issue is that after I login using twitter account I check my table User but is still empty,nothing is stored in database....?! |
Is your project open source? If not, can you debug the problem? |
No until now,I don't know how the bundle works to save data in database, I installed FosUserBundle too,I have made all configuration,I have a table in database and en Entity User?So why it dosn't works...? |
I can't help you without any information. Have you checked the logs, if the update statement is fired? If not take a look in the |
ok i see,just another stupid question,the bundle automatically saves the data during the authentication in DB or I have to create a code for saving using methods of the class TwitterUserProvider? |
Not magical, you wrote the |
I don't get you without code.I have just this in my action : $request = $this->get('request');
|
I know. But you created a So you should debug this method. |
Ok I understand that but how,in this method I had "username" in parameter so I must have username of twitter account : $request = $this->get('request'); $result = new TwitterUserProvider(); $result-> loadUserByUsername($username) ??
can you help me by some code... |
I spend two days with this bundle, I can do it by my self insted to use the famous TwitterUserProvider,they are no solution,how I debug this method!!! |
I installed FOSTwitterBundle using your tutorial here ,but I have an issue about how to save informations in my database of every user logged using his twitter account ?
I have this error :
_ErrorException: Catchable Fatal Error: Argument 2 passed to Skeleton\PanelBundle\Security\User\Provider\TwitterUserProvider::_construct() must be an instance of FOS\UserBundle\Entity\UserManager, instance of FOS\UserBundle\Doctrine\UserManager given, called in /var/www/skeleton/app/cache/dev/appDevDebugProjectContainer.php on line 1678 and defined in /var/www/skeleton/src/Skeleton/PanelBundle/Security/User/Provider/TwitterUserProvider.php line 34
here is my config.yml :
*services:
my.twitter.user:
class: Skeleton\PanelBundle\Security\User\Provider\TwitterUserProvider
arguments:
twitter_oauth: "@fos_twitter.api"
userManager: "@fos_user.user_manager"
validator: "@validator"
session: "@session" *
and security.yml :
*security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
I spend almost all day but no solution!
The text was updated successfully, but these errors were encountered: