Skip to content

Commit

Permalink
Refactor get-tweets.php to use Twitter library from Composer
Browse files Browse the repository at this point in the history
Delete the previously bundled library
  • Loading branch information
dregad committed Nov 14, 2020
1 parent b69bfce commit daa9366
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 1,815 deletions.
43 changes: 33 additions & 10 deletions get-tweets.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
<?php
include( 'config_defaults_inc.php' );
/**
* Retrieve recent mantisbt tweets and prints them as JSON
*
* Used as AJAX from custom.js
*/

session_start();
require_once("twitteroauth-master/twitteroauth/twitteroauth.php"); //Path to twitteroauth library
use Abraham\TwitterOAuth\TwitterOAuth;

function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
$connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
return $connection;
}
require_once 'config_defaults_inc.php';
require_once 'vendor/autoload.php';

$connection = getConnectionWithAccessToken( $g_twitter_consumer_key, $g_twitter_consumer_secret, $g_twitter_access_token, $g_twitter_access_token_secret );
session_start();

$tweets = $connection->get( 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=' . $g_twitter_username . "&count=" . $g_twitter_tweets_count );
/**
* Avoid PHPStorm unused variable warnings
* @var string $g_twitter_consumer_key
* @var string $g_twitter_consumer_secret
* @var string $g_twitter_access_token
* @var string $g_twitter_access_token_secret
* @var string $g_twitter_username
* @var int $g_twitter_tweets_count
*/

echo json_encode($tweets);
$twitter = new TwitterOAuth(
$g_twitter_consumer_key,
$g_twitter_consumer_secret,
$g_twitter_access_token,
$g_twitter_access_token_secret
);

$tweets = $twitter->get( 'statuses/user_timeline',
array(
'screen_name' => $g_twitter_username,
'count' => $g_twitter_tweets_count,
)
);

echo json_encode($tweets);
22 changes: 0 additions & 22 deletions twitteroauth-master/LICENSE

This file was deleted.

114 changes: 0 additions & 114 deletions twitteroauth-master/README.md

This file was deleted.

40 changes: 0 additions & 40 deletions twitteroauth-master/callback.php

This file was deleted.

12 changes: 0 additions & 12 deletions twitteroauth-master/clearsessions.php

This file was deleted.

10 changes: 0 additions & 10 deletions twitteroauth-master/config.php

This file was deleted.

21 changes: 0 additions & 21 deletions twitteroauth-master/connect.php

This file was deleted.

39 changes: 0 additions & 39 deletions twitteroauth-master/html.inc

This file was deleted.

Binary file removed twitteroauth-master/images/darker.png
Binary file not shown.
Binary file removed twitteroauth-master/images/lighter.png
Binary file not shown.
30 changes: 0 additions & 30 deletions twitteroauth-master/index.php

This file was deleted.

28 changes: 0 additions & 28 deletions twitteroauth-master/redirect.php

This file was deleted.

Loading

0 comments on commit daa9366

Please sign in to comment.