naffiq / yii2-twitter-api
Yii2 component wrapper for J7mbo/twitter-api-php
Installs: 1 362
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- j7mbo/twitter-api-php: ^1.0.0
- yiisoft/yii2: ^2.0.0
Requires (Dev)
- codeclimate/php-test-reporter: ^0.4.4
This package is auto-updated.
Last update: 2024-11-18 17:12:26 UTC
README
This package provides component wrapper for J7mbo/twitter-api-php library. Basically it just helps you to move settings to your app config.
Installation
The preferred way to install this package is through composer:
$ composer require naffiq/yii2-twitter-api
Configuration
Add following code to your components config section:
<?php return [ // Your app settings ... 'components' => [ // Other components ... 'twitter' => [ 'class' => 'naffiq\twitterapi\TwitterAPI', 'oauthAccessToken' => 'YOUR_OAUTH_ACCESS_TOKEN', 'oauthAccessTokenSecret' => 'YOUR_OAUTH_ACCESS_TOKEN', 'consumerKey' => 'YOUR_CONSUMER_KEY', 'consumerSecret' => 'YOUR_CONSUMER_SECRET' ] ] // ... ];
And we are ready to roll
Usage
Once you set up the component, you can use all of the J7mbo/twitter-api-php library's methods, just like this:
<?php /** * @var \naffiq\twitterapi\TwitterAPI $twitter */ $twitter = \Yii::$app->get('twitter'); $url = 'https://api.twitter.com/1.1/blocks/create.json'; $requestMethod = 'POST'; $postFields = [ 'screen_name' => 'usernameToBlock', 'skip_status' => '1' ]; $twitter->buildOauth($url, $requestMethod) ->setPostfields($postFields) ->performRequest();