endroid/twitter-bundle

Endroid Twitter Bundle for Symfony

Installs: 8 013

Dependents: 1

Stars: 12

Watchers: 3

Forks: 3

Language: PHP

1.1.6 2015-07-04 19:53 UTC

README

By endroid

Build Status Latest Stable Version Total Downloads

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

Use Composer to install the bundle.

$ composer require endroid/twitter-bundle

Then 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');
$tweets = json_decode($response->getContent());

Versioning

Semantic versioning (semver) is applied as much as possible.

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.