PHP code example of naffiq / yii2-twitter-api

1. Go to this page and download the library: Download naffiq/yii2-twitter-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

naffiq / yii2-twitter-api example snippets



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'
        ]        
    ]
    // ...
];



/**
 * @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();