Skip to content

ollietb/EndroidTwitterBundle

Repository files navigation

Endroid Twitter Bundle

By endroid

Build Status

This bundle enables you to use Endroid Twitter as a service in your Symfony project. It also provides an API controller that takes a local API request, adds an OAuth signature to it and returns the corresponding Twitter API response. This enables you to expose the Twitter API on your own domain without having to bother about OAuth signing your requests.

For more information see the endroid/Twitter repository and the Twitter API.

knpbundles.com

Requirements

Installation

Add in your composer.json

{
    "require": {
        "endroid/twitter-bundle": "dev-master"
    }
}

Install the bundle

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update endroid/twitter-bundle

Composer will install the bundle to your project's vendor/endroid directory.

Enable the bundle via the kernel

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Endroid\Bundle\TwitterBundle\EndroidTwitterBundle(),
    );
}

Configuration

config.yml

endroid_twitter:
    consumer_key: "..."
    consumer_secret: "..."
    access_token: "..."
    access_token_secret: "..."

Routing

If you don't want to expose the Twitter API via your application, you can skip this section.

EndroidTwitterBundle:
    resource:	"@EndroidTwitterBundle/Controller/"
    type:		annotation
    prefix:		/twitterapi

This exposes the Twitter API via /twitterapi. This means that instead of sending a signed request to https://dev.twitter.com/docs/api/1.1/* you can now send an unsigned request to /twitterapi/*. Make sure you secure this area if you don't want others to be able to post on your behalf.

Usage

After installation and configuration, the service can be directly referenced from within your controllers.

<?php

$twitter = $this->get('endroid.twitter');

// Retrieve the user's timeline
$tweets = $twitter->getTimeline(array(
    'count' => 5
));

// Or retrieve the timeline using the generic query method
$response = $twitter->query('statuses/user_timeline', 'GET', 'json', $parameters);
$tweets = json_decode($response->getContent());

License

This bundle is under the MIT license. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.