Added Twitter auth command and some base functions.
This commit is contained in:
parent
eafa258d7a
commit
81b0abfd91
5 changed files with 289 additions and 7 deletions
|
@ -15,7 +15,8 @@
|
|||
"erusev/parsedown": "~1.6",
|
||||
"geoip2/geoip2": "~2.0",
|
||||
"twig/extensions": "^1.5",
|
||||
"filp/whoops": "^2.2"
|
||||
"filp/whoops": "^2.2",
|
||||
"jublonet/codebird-php": "^3.1"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
|
|
191
composer.lock
generated
191
composer.lock
generated
|
@ -4,20 +4,20 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "eecb2be3db098c1aae02a69d52791f7d",
|
||||
"content-hash": "3d0e94350450c6e4148bf7a0ea7ce697",
|
||||
"packages": [
|
||||
{
|
||||
"name": "composer/ca-bundle",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/composer/ca-bundle.git",
|
||||
"reference": "8afa52cd417f4ec417b4bfe86b68106538a87660"
|
||||
"reference": "558f321c52faeb4828c03e7dc0cfe39a09e09a2d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/composer/ca-bundle/zipball/8afa52cd417f4ec417b4bfe86b68106538a87660",
|
||||
"reference": "8afa52cd417f4ec417b4bfe86b68106538a87660",
|
||||
"url": "https://api.github.com/repos/composer/ca-bundle/zipball/558f321c52faeb4828c03e7dc0cfe39a09e09a2d",
|
||||
"reference": "558f321c52faeb4828c03e7dc0cfe39a09e09a2d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -60,7 +60,127 @@
|
|||
"ssl",
|
||||
"tls"
|
||||
],
|
||||
"time": "2018-10-18T06:09:13+00:00"
|
||||
"time": "2019-01-28T09:30:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/installers",
|
||||
"version": "v1.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/composer/installers.git",
|
||||
"reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/composer/installers/zipball/cfcca6b1b60bc4974324efb5783c13dca6932b5b",
|
||||
"reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "^1.0"
|
||||
},
|
||||
"replace": {
|
||||
"roundcube/plugin-installer": "*",
|
||||
"shama/baton": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer": "1.0.*@dev",
|
||||
"phpunit/phpunit": "^4.8.36"
|
||||
},
|
||||
"type": "composer-plugin",
|
||||
"extra": {
|
||||
"class": "Composer\\Installers\\Plugin",
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Composer\\Installers\\": "src/Composer/Installers"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Kyle Robinson Young",
|
||||
"email": "kyle@dontkry.com",
|
||||
"homepage": "https://github.com/shama"
|
||||
}
|
||||
],
|
||||
"description": "A multi-framework Composer library installer",
|
||||
"homepage": "https://composer.github.io/installers/",
|
||||
"keywords": [
|
||||
"Craft",
|
||||
"Dolibarr",
|
||||
"Eliasis",
|
||||
"Hurad",
|
||||
"ImageCMS",
|
||||
"Kanboard",
|
||||
"Lan Management System",
|
||||
"MODX Evo",
|
||||
"Mautic",
|
||||
"Maya",
|
||||
"OXID",
|
||||
"Plentymarkets",
|
||||
"Porto",
|
||||
"RadPHP",
|
||||
"SMF",
|
||||
"Thelia",
|
||||
"WolfCMS",
|
||||
"agl",
|
||||
"aimeos",
|
||||
"annotatecms",
|
||||
"attogram",
|
||||
"bitrix",
|
||||
"cakephp",
|
||||
"chef",
|
||||
"cockpit",
|
||||
"codeigniter",
|
||||
"concrete5",
|
||||
"croogo",
|
||||
"dokuwiki",
|
||||
"drupal",
|
||||
"eZ Platform",
|
||||
"elgg",
|
||||
"expressionengine",
|
||||
"fuelphp",
|
||||
"grav",
|
||||
"installer",
|
||||
"itop",
|
||||
"joomla",
|
||||
"kohana",
|
||||
"laravel",
|
||||
"lavalite",
|
||||
"lithium",
|
||||
"magento",
|
||||
"majima",
|
||||
"mako",
|
||||
"mediawiki",
|
||||
"modulework",
|
||||
"modx",
|
||||
"moodle",
|
||||
"osclass",
|
||||
"phpbb",
|
||||
"piwik",
|
||||
"ppi",
|
||||
"puppet",
|
||||
"pxcms",
|
||||
"reindex",
|
||||
"roundcube",
|
||||
"shopware",
|
||||
"silverstripe",
|
||||
"sydes",
|
||||
"symfony",
|
||||
"typo3",
|
||||
"wordpress",
|
||||
"yawik",
|
||||
"zend",
|
||||
"zikula"
|
||||
],
|
||||
"time": "2018-08-27T06:10:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/lexer",
|
||||
|
@ -332,6 +452,65 @@
|
|||
],
|
||||
"time": "2018-04-10T15:32:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jublonet/codebird-php",
|
||||
"version": "3.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jublonet/codebird-php.git",
|
||||
"reference": "100a8e8f1928a5738b4476f0caf83f2c2ba6da5b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/jublonet/codebird-php/zipball/100a8e8f1928a5738b4476f0caf83f2c2ba6da5b",
|
||||
"reference": "100a8e8f1928a5738b4476f0caf83f2c2ba6da5b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer/installers": "~1.0",
|
||||
"ext-hash": "*",
|
||||
"ext-json": "*",
|
||||
"lib-openssl": "*",
|
||||
"php": ">=5.5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": ">=3.7",
|
||||
"satooshi/php-coveralls": ">=0.6",
|
||||
"squizlabs/php_codesniffer": "2.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-3.0+"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Joshua Atkins",
|
||||
"email": "joshua.atkins@jublo.net",
|
||||
"homepage": "http://atkins.im/",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "J.M.",
|
||||
"email": "jm@jublo.net",
|
||||
"homepage": "http://mynetx.net/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Easy access to the Twitter REST API, Collections API, Streaming API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.",
|
||||
"homepage": "https://www.jublo.net/projects/codebird/php",
|
||||
"keywords": [
|
||||
"api",
|
||||
"networking",
|
||||
"twitter"
|
||||
],
|
||||
"time": "2016-02-15T18:38:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "maxmind-db/reader",
|
||||
"version": "v1.4.1",
|
||||
|
|
|
@ -46,3 +46,7 @@ secret_key = secret_key_for_generating_csrf_tokens
|
|||
[Proxy]
|
||||
enabled = true
|
||||
secret_key = change_this_or_i_will_beat_you_up
|
||||
|
||||
[Twitter]
|
||||
api_key = <consumer key>
|
||||
api_secret = <consumer secret key>
|
||||
|
|
35
misuzu.php
35
misuzu.php
|
@ -44,6 +44,7 @@ require_once 'src/pagination.php';
|
|||
require_once 'src/perms.php';
|
||||
require_once 'src/string.php';
|
||||
require_once 'src/tpl.php';
|
||||
require_once 'src/twitter.php';
|
||||
require_once 'src/url.php';
|
||||
require_once 'src/zalgo.php';
|
||||
require_once 'src/Forum/forum.php';
|
||||
|
@ -311,6 +312,40 @@ MIG;
|
|||
echo "Template for '{$namespace}' has been created." . PHP_EOL;
|
||||
break;
|
||||
|
||||
case 'twitter-auth':
|
||||
$apiKey = config_get('Twitter', 'api_key');
|
||||
$apiSecret = config_get('Twitter', 'api_secret');
|
||||
|
||||
if (empty($apiKey) || empty($apiSecret)) {
|
||||
echo 'No Twitter api keys set in config.' . PHP_EOL;
|
||||
break;
|
||||
}
|
||||
|
||||
twitter_init($apiKey, $apiSecret);
|
||||
echo 'Twitter Authentication' . PHP_EOL;
|
||||
|
||||
$authPage = twitter_auth_create();
|
||||
|
||||
if (empty($authPage)) {
|
||||
echo 'Request to begin authentication failed.' . PHP_EOL;
|
||||
break;
|
||||
}
|
||||
|
||||
echo 'Go to the page below and paste the pin code displayed.' . PHP_EOL . $authPage . PHP_EOL;
|
||||
|
||||
$pin = readline('Pin: ');
|
||||
$authComplete = twitter_auth_complete($pin);
|
||||
|
||||
if (empty($authComplete)) {
|
||||
echo 'Invalid pin code.' . PHP_EOL;
|
||||
break;
|
||||
}
|
||||
|
||||
echo 'Authentication successful!' . PHP_EOL
|
||||
. "Token: {$authComplete['token']}" . PHP_EOL
|
||||
. "Token Secret: {$authComplete['token_secret']}" . PHP_EOL;
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'Unknown command.' . PHP_EOL;
|
||||
break;
|
||||
|
|
63
src/twitter.php
Normal file
63
src/twitter.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
use Codebird\Codebird;
|
||||
|
||||
function twitter_init(
|
||||
string $apiKey,
|
||||
string $apiSecretKey,
|
||||
?string $token = null,
|
||||
?string $tokenSecret = null
|
||||
): void {
|
||||
Codebird::setConsumerKey($apiKey, $apiSecretKey);
|
||||
|
||||
if (!is_null($token) && !is_null($tokenSecret)) {
|
||||
twitter_token_set($token, $tokenSecret);
|
||||
}
|
||||
}
|
||||
|
||||
function twitter_token_set(string $token, string $tokenSecret): void
|
||||
{
|
||||
Codebird::getInstance()->setToken($token, $tokenSecret);
|
||||
}
|
||||
|
||||
function twitter_auth_create(): ?string
|
||||
{
|
||||
$codebird = Codebird::getInstance();
|
||||
$reply = $codebird->oauth_requestToken([
|
||||
'oauth_callback' => 'oob',
|
||||
]);
|
||||
|
||||
if (!$reply) {
|
||||
return null;
|
||||
}
|
||||
|
||||
twitter_token_set($reply->oauth_token, $reply->oauth_token_secret);
|
||||
|
||||
return $codebird->oauth_authorize();
|
||||
}
|
||||
|
||||
function twitter_auth_complete(string $pin): array
|
||||
{
|
||||
$reply = Codebird::getInstance()->oauth_accessToken([
|
||||
'oauth_verifier' => $pin,
|
||||
]);
|
||||
|
||||
if (!$reply) {
|
||||
return [];
|
||||
}
|
||||
|
||||
twitter_token_set($reply->oauth_token, $reply->oauth_token_secret);
|
||||
|
||||
return [
|
||||
'token' => $reply->oauth_token,
|
||||
'token_secret' => $reply->oauth_token_secret,
|
||||
];
|
||||
}
|
||||
|
||||
function twitter_tweet_post(string $text): void
|
||||
{
|
||||
$params = [
|
||||
'status' => $text,
|
||||
];
|
||||
|
||||
Codebird::getInstance()->statuses_update($params);
|
||||
}
|
Loading…
Add table
Reference in a new issue