PHPackages                             friendsofsymfony/twitter-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. friendsofsymfony/twitter-bundle

Abandoned → [hwi/oauth-bundle](/?search=hwi%2Foauth-bundle)ArchivedSymfony-bundle[Authentication &amp; Authorization](/categories/authentication)

friendsofsymfony/twitter-bundle
===============================

Symfony FOSTwitterBundle

1.0.0(14y ago)15442.2k36[9 issues](https://github.com/FriendsOfSymfony/FOSTwitterBundle/issues)[10 PRs](https://github.com/FriendsOfSymfony/FOSTwitterBundle/pulls)MITPHPPHP &gt;=5.3.2

Since Dec 13Pushed 11y ago17 watchersCompare

[ Source](https://github.com/FriendsOfSymfony/FOSTwitterBundle)[ Packagist](https://packagist.org/packages/friendsofsymfony/twitter-bundle)[ Docs](http://friendsofsymfony.github.com)[ RSS](/packages/friendsofsymfony-twitter-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

DEPRECATED
==========

[](#deprecated)

See [HWIOAuthBundle](https://github.com/hwi/HWIOAuthBundle) instead
-------------------------------------------------------------------

[](#see-hwioauthbundle-instead)

Introduction
============

[](#introduction)

This Bundle enables integration with Twitter PHP. Furthermore it also provides a Symfony2 authentication provider so that users can login to a Symfony2 application via Twitter. Furthermore via custom user provider support the Twitter login can also be integrated with other data sources like the database based solution provided by FOSUserBundle.

`If you are using Symfony 2.0 switch to the branch v1.0 of TwitterBundle or use the tag 1.0.0`

[![Build Status](https://camo.githubusercontent.com/0d9013b61b4a06b8e98d3f4429a5785c8a9e2e720a1fa2cd2ddf1a058f7cfe85/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f467269656e64734f6653796d666f6e792f464f535477697474657242756e646c652e706e67)](http://travis-ci.org/FriendsOfSymfony/FOSTwitterBundle)

Installation
============

[](#installation)

1. Add this bundle and Abraham Williams' Twitter library to your project as Git submodules:

    ```
     $ git submodule add git://github.com/FriendsOfSymfony/FOSTwitterBundle.git vendor/bundles/FOS/TwitterBundle
     $ git submodule add git://github.com/kertz/twitteroauth.git vendor/twitteroauth

    ```

> **Note:** The kertz/twitteroauth is patched to be compatible with FOSTwitterBundle

2. Register the namespace `FOS` to your project's autoloader bootstrap script:

    ```
     //app/autoload.php
     $loader->registerNamespaces(array(
           // ...
           'FOS'    => __DIR__.'/../vendor/bundles',
           // ...
     ));

    ```
3. Add this bundle to your application's kernel:

    ```
     //app/AppKernel.php
     public function registerBundles()
     {
         return array(
             // ...
             new FOS\TwitterBundle\FOSTwitterBundle(),
             // ...
         );
     }

    ```
4. Configure the `twitter` service in your YAML configuration:

    ```
       #app/config/config.yml
       fos_twitter:
           file: %kernel.root_dir%/../vendor/twitteroauth/twitteroauth/twitteroauth.php
           consumer_key: xxxxxx
           consumer_secret: xxxxxx
           callback_url: http://www.example.com/login_check

    ```
5. Add the following configuration to use the security component:

    ```
       #app/config/security.yml
       security:
           providers:
               fos_twitter:
                   id: fos_twitter.auth
           firewalls:
               secured:
                   pattern:   /secured/.*
                   fos_twitter: true
               public:
                   pattern:   /.*
                   anonymous: true
                   fos_twitter: true
                   logout: true
           access_control:
               - { path: /.*, role: [IS_AUTHENTICATED_ANONYMOUSLY] }

    ```

Using Twitter @Anywhere
-----------------------

[](#using-twitter-anywhere)

> **Note:** If you want the Security Component to work with Twitter @Anywhere, you need to send a request to the configured check path upon successful client authentication (see  for a sample configuration).

A templating helper is included for using Twitter @Anywhere. To use it, first call the `->setup()` method toward the top of your DOM:

```

      {{ twitter_anywhere_setup() }}

```

Once that's done, you can queue up JavaScript to be run once the library is actually loaded:

```

    {{ twitter_anywhere_setConfig('callbackURL', 'http://www.example.com/login_check') }}
    {{ twitter_anywhere_queue('T("#twitter_connect").connectButton()') }}

```

Finally, call the `->initialize()` method toward the bottom of the DOM:

```

    {{ twitter_anywhere_initialize() }}

```

### Configuring Twitter @Anywhere

[](#configuring-twitter-anywhere)

You can set configuration using the templating helper. with the setConfig() method.

Example Custom User Provider using the FOSUserBundle
----------------------------------------------------

[](#example-custom-user-provider-using-the-fosuserbundle)

To use this provider you will need to add a new service in your config.yml

```
# app/config/config.yml
services:
        my.twitter.user:
            class: Acme\YourBundle\Security\User\Provider\TwitterUserProvider
            arguments:
                twitter_oauth: "@fos_twitter.api"
                userManager: "@fos_user.user_manager"
                validator: "@validator"
                session: "@session"
```

Also you would need some new properties and methods in your User model class.

```
