Compare commits

...

28 commits

Author SHA1 Message Date
Hypolite Petovan b76f143e60 Merge pull request 'Audon audioplayer App' (#1414) from loma-one/friendica-addons:develop into develop
Reviewed-on: friendica/friendica-addons#1414
2023-08-18 18:41:32 +02:00
loma-one 94a4c93368 audon/lang/C/messages.po aktualisiert 2023-08-18 18:41:32 +02:00
loma-one dfbf8d4acf audon/lang/C/messages.po hinzugefügt 2023-08-18 18:41:32 +02:00
loma-one 983d334ef5 audon/C/messages.po gelöscht 2023-08-18 18:41:32 +02:00
loma-one 2fa030aa65 audon/C/messages.po aktualisiert 2023-08-18 18:41:32 +02:00
loma-one 7ef59da623 audon/C/messages.po hinzugefügt 2023-08-18 18:41:32 +02:00
loma-one 476fdd1bb7 audon/lang/C gelöscht
Signed-off-by: loma-one <loma-one@noreply.git.friendi.ca>
2023-08-18 18:41:32 +02:00
loma-one 9786b605b6 audon/lang/C aktualisiert
now :)
2023-08-18 18:41:32 +02:00
loma-one a26c2c9758 audon/lang/C aktualisiert 2023-08-18 18:41:32 +02:00
loma-one 8ef6fafdaa audon/audon.php aktualisiert 2023-08-18 18:41:32 +02:00
loma-one c93e6840fa audon/audon.php aktualisiert 2023-08-18 18:41:32 +02:00
loma-one 65d8e467fe audon/templates/admin.tpl aktualisiert 2023-08-18 18:41:32 +02:00
loma-one 38460a4cff audon/audon.php aktualisiert 2023-08-18 18:41:32 +02:00
loma-one db218ac4f6 audon/audon.php aktualisiert 2023-08-18 18:41:32 +02:00
loma-one e391a65695 „audon/audon.php“ ändern 2023-08-18 18:41:32 +02:00
loma-one a3dc032a51 „audon/lang/C“ hinzufügen 2023-08-18 18:41:32 +02:00
loma-one 9035144e5b Dateien hochladen nach „audon/templates“ 2023-08-18 18:41:32 +02:00
loma-one 4e17f3c9db „audon/admin.tpl“ löschen 2023-08-18 18:41:32 +02:00
loma-one 630f4ab991 „audon/messages.po“ löschen 2023-08-18 18:41:32 +02:00
loma-one effa19c467 Audon Audio Chat based on the WebRTC Addon
This Addon based on webrtc. Audon is a service of realtime audio chat.
With small changes, the WebRTC addon could be adapted to Audon so that it can be loaded into an iframe. In the ifram, the Friendica handle can be connected and a room opened. Audio conversations between Friendica users are possible.
https://github.com/friendica/friendica-addons/pull/1357
2023-08-18 18:41:32 +02:00
Hypolite Petovan 6d200dd419 Merge pull request 'Twitter: Fix posting' (#1413) from heluecht/friendica-addons:resize into develop
Reviewed-on: friendica/friendica-addons#1413
2023-08-16 20:58:34 +02:00
Michael 340f3f41d7 Twitter: Fix posting 2023-08-16 14:58:04 -04:00
Hypolite Petovan 886638f8a5 Merge pull request 'Simplified status display' (#1412) from heluecht/friendica-addons:resize into develop
Reviewed-on: friendica/friendica-addons#1412
2023-08-16 12:27:28 +02:00
Michael 339c88353b Test the connection when API credential changed 2023-08-16 12:27:28 +02:00
Michael a3e24a55ec Last status is split for better readability 2023-08-16 12:27:28 +02:00
Michael 3d6748eaf7 Simplified status display 2023-08-16 12:27:28 +02:00
Hypolite Petovan fb9e6e5df6 Merge pull request 'Nluesky/Twitter: Resize picture before uploading' (#1411) from heluecht/friendica-addons:resize into develop
Reviewed-on: friendica/friendica-addons#1411
2023-08-15 22:38:49 +02:00
Michael 8b66b3a194 Nluesky/Twitter: Resize picture before uploading 2023-08-15 20:25:17 +00:00
8 changed files with 294 additions and 34 deletions

6
audon/README.md Normal file
View file

@ -0,0 +1,6 @@
Audon Addon
=============
This is a quick and dirty addon to add a [Audon][1] website as an app. This Addon based on webrtc. Audon is a service of realtime audio chat
[1]: https://codeberg.org/nmkj/audon

69
audon/audon.php Normal file
View file

@ -0,0 +1,69 @@
<?php
/*
* Name: Audon Application
* Description: add a Audon instance. Based on webRTC Addon
* Version: 0.1
* Author: Stephen Mahood <https://friends.mayfirst.org/profile/marxistvegan>
* Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
* Author: Matthias Ebers <https://loma.ml/profile/feb>
*/
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\DI;
function audon_install()
{
Hook::register('app_menu', __FILE__, 'audon_app_menu');
}
function audon_app_menu(array &$b)
{
$b['app_menu'][] = '<div class="app-title"><a href="audon">' . DI::l10n()->t('Audon Audiochat') . '</a></div>';
}
function audon_addon_admin(string &$o)
{
$t = Renderer::getMarkupTemplate('admin.tpl', 'addon/audon/');
$o = Renderer::replaceMacros($t, [
'$submit' => DI::l10n()->t('Save Settings'),
'$audonurl' => [
'audonurl',
DI::l10n()->t('Audon Base URL'),
DI::config()->get('audon','audonurl'),
DI::l10n()->t('Page your users will create an Audon audio chat room on. For example you could use https://audon.space.'),
],
]);
}
function audon_addon_admin_post()
{
DI::config()->set('audon', 'audonurl', trim($_POST['audonurl'] ?? ''));
}
/**
* This is a statement rather than an actual function definition. The simple
* existence of this method is checked to figure out if the addon offers a
* module.
*/
function audon_module() {}
function audon_content(): string
{
$o = '';
/* landingpage to create chatrooms */
$audonurl = DI::config()->get('audon', 'audonurl');
/* embedd the landing page in an iframe */
$o .= '<h2>' . DI::l10n()->t('Audio Chat') . '</h2>';
$o .= '<p>' . DI::l10n()->t('Audon is an audio conferencing tool. Connect your account to Audon and create a room. Share the generated link to talk to other participants.') . '</p>';
if ($audonurl == '') {
$o .= '<p>' . DI::l10n()->t('Please contact your Friendica administrator to remind them to configure the Audon addon.') . '</p>';
} else {
$o .= '<iframe src="' . $audonurl . '" width="740px" height="600px"></iframe>';
}
return $o;
}

52
audon/lang/C/messages.po Normal file
View file

@ -0,0 +1,52 @@
# ADDON audon
# Copyright (C)
# This file is distributed under the same license as the Friendica audon addon package.
#
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-08-18 18:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: audon.php:22
msgid "Audon Audiochat"
msgstr ""
#: audon.php:29
msgid "Save Settings"
msgstr ""
#: audon.php:32
msgid "Audon Base URL"
msgstr ""
#: audon.php:34
msgid ""
"Page your users will create an Audon audio chat room on. For example you "
"could use https://audon.space."
msgstr ""
#: audon.php:60
msgid "Audio Chat"
msgstr ""
#: audon.php:61
msgid ""
"Audon is an audio conferencing tool. Connect your account to Audon and "
"create a room. Share the generated link to talk to other participants."
msgstr ""
#: audon.php:63
msgid ""
"Please contact your Friendica administrator to remind them to configure the "
"Audon addon."
msgstr ""

View file

@ -0,0 +1,2 @@
{{include file="field_input.tpl" field=$audonurl}}
<button type="submit">{{$submit}}</button>

View file

@ -43,6 +43,7 @@ use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Object\Image;
use Friendica\Protocol\Activity;
use Friendica\Protocol\Relay;
use Friendica\Util\DateTimeFormat;
@ -50,6 +51,7 @@ use Friendica\Util\Strings;
const BLUESKY_DEFAULT_POLL_INTERVAL = 10; // given in minutes
const BLUESKY_HOST = 'https://bsky.app'; // Hard wired until Bluesky will run on multiple systems
const BLUESKY_IMAGE_SIZE = [1000000, 500000, 100000, 50000];
function bluesky_install()
{
@ -634,6 +636,12 @@ function bluesky_create_post(array $item, stdClass $root = null, stdClass $paren
if ($key == count($msg['parts']) - 1) {
$record = bluesky_add_embed($uid, $msg, $record);
if (empty($record)) {
if (Worker::getRetrial() < 3) {
Worker::defer();
}
return;
}
}
$post = [
@ -644,6 +652,9 @@ function bluesky_create_post(array $item, stdClass $root = null, stdClass $paren
$parent = bluesky_xrpc_post($uid, 'com.atproto.repo.createRecord', $post);
if (empty($parent)) {
if ($part == 0) {
Worker::defer();
}
return;
}
Logger::debug('Posting done', ['return' => $parent]);
@ -663,6 +674,7 @@ function bluesky_get_urls(string $body): array
// Remove all hashtag and mention links
$body = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $body);
$body = BBCode::expandVideoLinks($body);
$urls = [];
// Search for pure links
@ -746,12 +758,15 @@ function bluesky_add_embed(int $uid, array $msg, array $record): array
if (($msg['type'] != 'link') && !empty($msg['images'])) {
$images = [];
foreach ($msg['images'] as $image) {
$photo = Photo::selectFirst(['resource-id'], ['id' => $image['id']]);
$photo = Photo::selectFirst([], ["`resource-id` = ? AND `scale` > ?", $photo['resource-id'], 0], ['order' => ['scale']]);
$blob = bluesky_upload_blob($uid, $photo);
if (!empty($blob) && count($images) < 4) {
$images[] = ['alt' => $image['description'] ?? '', 'image' => $blob];
if (count($images) == 4) {
continue;
}
$photo = Photo::selectFirst([], ['id' => $image['id']]);
$blob = bluesky_upload_blob($uid, $photo);
if (empty($blob)) {
return [];
}
$images[] = ['alt' => $image['description'] ?? '', 'image' => $blob];
}
if (!empty($images)) {
$record['embed'] = ['$type' => 'app.bsky.embed.images', 'images' => $images];
@ -778,13 +793,29 @@ function bluesky_add_embed(int $uid, array $msg, array $record): array
function bluesky_upload_blob(int $uid, array $photo): ?stdClass
{
$retrial = Worker::getRetrial();
$content = Photo::getImageForPhoto($photo);
$picture = new Image($content, $photo['type']);
$height = $picture->getHeight();
$width = $picture->getWidth();
$size = strlen($content);
$picture = Photo::resizeToFileSize($picture, BLUESKY_IMAGE_SIZE[$retrial]);
$new_height = $picture->getHeight();
$new_width = $picture->getWidth();
$content = $picture->asString();
$new_size = strlen($content);
Logger::info('Uploading', ['uid' => $uid, 'retrial' => $retrial, 'height' => $new_height, 'width' => $new_width, 'size' => $new_size, 'orig-height' => $height, 'orig-width' => $width, 'orig-size' => $size]);
$data = bluesky_post($uid, '/xrpc/com.atproto.repo.uploadBlob', $content, ['Content-type' => $photo['type'], 'Authorization' => ['Bearer ' . bluesky_get_token($uid)]]);
if (empty($data)) {
Logger::info('Uploading failed', ['uid' => $uid, 'retrial' => $retrial, 'height' => $new_height, 'width' => $new_width, 'size' => $new_size, 'orig-height' => $height, 'orig-width' => $width, 'orig-size' => $size]);
return null;
}
Logger::debug('Uploaded blob', ['return' => $data]);
Logger::debug('Uploaded blob', ['return' => $data, 'uid' => $uid, 'retrial' => $retrial, 'height' => $new_height, 'width' => $new_width, 'size' => $new_size, 'orig-height' => $height, 'orig-width' => $width, 'orig-size' => $size]);
return $data->blob;
}

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-08-09 19:59+0000\n"
"POT-Creation-Date: 2023-08-16 03:27+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,42 +17,46 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: twitter.php:80
#: twitter.php:84
msgid "Post to Twitter"
msgstr ""
#: twitter.php:117
#: twitter.php:123
msgid "No status."
msgstr ""
#: twitter.php:129
msgid "Allow posting to Twitter"
msgstr ""
#: twitter.php:117
#: twitter.php:129
msgid ""
"If enabled all your <strong>public</strong> postings can be posted to the "
"associated Twitter account. You can choose to do so by default (here) or for "
"every posting separately in the posting options when writing the entry."
msgstr ""
#: twitter.php:118
#: twitter.php:130
msgid "Send public postings to Twitter by default"
msgstr ""
#: twitter.php:119
#: twitter.php:131
msgid "API Key"
msgstr ""
#: twitter.php:120
#: twitter.php:132
msgid "API Secret"
msgstr ""
#: twitter.php:121
#: twitter.php:133
msgid "Access Token"
msgstr ""
#: twitter.php:122
#: twitter.php:134
msgid "Access Secret"
msgstr ""
#: twitter.php:123
#: twitter.php:135
msgid ""
"Each user needs to register their own app to be able to post to Twitter. "
"Please visit https://developer.twitter.com/en/portal/projects-and-apps to "
@ -61,6 +65,14 @@ msgid ""
"in the app settings."
msgstr ""
#: twitter.php:128
#: twitter.php:136
msgid "Last Status Summary"
msgstr ""
#: twitter.php:137
msgid "Last Status Content"
msgstr ""
#: twitter.php:142
msgid "Twitter Export"
msgstr ""

View file

@ -4,4 +4,6 @@
{{include file="field_input.tpl" field=$api_key}}
{{include file="field_input.tpl" field=$api_secret}}
{{include file="field_input.tpl" field=$access_token}}
{{include file="field_input.tpl" field=$access_secret}}
{{include file="field_input.tpl" field=$access_secret}}
{{include file="field_input.tpl" field=$status_title}}
{{include file="field_textarea.tpl" field=$status}}

View file

@ -47,12 +47,12 @@ use Friendica\Model\Post;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Model\Photo;
use Friendica\Object\Image;
use Friendica\Util\Images;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
const TWITTER_MAX_IMAGE_SIZE = 500000;
const TWITTER_IMAGE_SIZE = [2000000, 1000000, 500000, 100000, 50000];
function twitter_install()
{
@ -94,12 +94,25 @@ function twitter_settings_post()
return;
}
$api_key = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'api_key');
$api_secret = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'api_secret');
$access_token = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'access_token');
$access_secret = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'access_secret');
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'post', (bool)$_POST['twitter-enable']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'post_by_default', (bool)$_POST['twitter-default']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'api_key', $_POST['twitter-api-key']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'api_secret', $_POST['twitter-api-secret']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'access_token', $_POST['twitter-access-token']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'access_secret', $_POST['twitter-access-secret']);
if (
empty(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'last_status')) ||
($api_key != $_POST['twitter-api-key']) || ($api_secret != $_POST['twitter-api-secret']) ||
($access_token != $_POST['twitter-access-token']) || ($access_secret != $_POST['twitter-access-secret'])
) {
twitter_test_connection(DI::userSession()->getLocalUserId());
}
}
function twitter_settings(array &$data)
@ -116,6 +129,14 @@ function twitter_settings(array &$data)
$access_token = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'access_token');
$access_secret = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'access_secret');
$last_status = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'last_status');
if (!empty($last_status['code']) && !empty($last_status['reason'])) {
$status_title = sprintf('%d - %s', $last_status['code'], $last_status['reason']);
} else {
$status_title = DI::l10n()->t('No status.');
}
$status_content = $last_status['content'] ?? '';
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/twitter/');
$html = Renderer::replaceMacros($t, [
'$enable' => ['twitter-enable', DI::l10n()->t('Allow posting to Twitter'), $enabled, DI::l10n()->t('If enabled all your <strong>public</strong> postings can be posted to the associated Twitter account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.')],
@ -125,6 +146,8 @@ function twitter_settings(array &$data)
'$access_token' => ['twitter-access-token', DI::l10n()->t('Access Token'), $access_token],
'$access_secret' => ['twitter-access-secret', DI::l10n()->t('Access Secret'), $access_secret],
'$help' => DI::l10n()->t('Each user needs to register their own app to be able to post to Twitter. Please visit https://developer.twitter.com/en/portal/projects-and-apps to register a project. Inside the project you then have to register an app. You will find the needed data for the connector on the page "Keys and token" in the app settings.'),
'$status_title' => ['twitter-status-title', DI::l10n()->t('Last Status Summary'), $status_title, '', '', 'readonly'],
'$status' => ['twitter-status', DI::l10n()->t('Last Status Content'), $status_content, '', '', 'readonly'],
]);
$data = [
@ -216,16 +239,19 @@ function twitter_post_hook(array &$b)
if (!empty($msgarr['images']) || !empty($msgarr['remote_images'])) {
Logger::info('Got images', ['id' => $b['id'], 'images' => $msgarr['images'] ?? []]);
$retrial = Worker::getRetrial();
if ($retrial > 4) {
return;
}
foreach ($msgarr['images'] ?? [] as $image) {
if (count($media_ids) == 4) {
continue;
}
try {
$media_ids[] = twitter_upload_image($b['uid'], $image, $b);
} catch (\Throwable $th) {
Logger::warning('Error while uploading image', ['image' => $image, 'code' => $th->getCode(), 'message' => $th->getMessage()]);
// Currently don't defer to avoid a loop.
//Worker::defer();
$media_ids[] = twitter_upload_image($b['uid'], $image, $retrial);
} catch (RequestException $exception) {
Logger::warning('Error while uploading image', ['image' => $image, 'code' => $exception->getCode(), 'message' => $exception->getMessage()]);
Worker::defer();
return;
}
}
@ -238,9 +264,17 @@ function twitter_post_hook(array &$b)
try {
$id = twitter_post_status($b['uid'], $part, $media_ids, $in_reply_to_tweet_id);
Logger::info('twitter_post send', ['part' => $key, 'id' => $b['id'], 'result' => $id]);
} catch (\Throwable $th) {
Logger::warning('Error while posting message', ['part' => $key, 'id' => $b['id'], 'code' => $th->getCode(), 'message' => $th->getMessage()]);
Worker::defer();
} catch (RequestException $exception) {
Logger::warning('Error while posting message', ['part' => $key, 'id' => $b['id'], 'code' => $exception->getCode(), 'message' => $exception->getMessage()]);
$status = [
'code' => $exception->getCode(),
'reason' => $exception->getResponse()->getReasonPhrase(),
'content' => $exception->getMessage()
];
DI::pConfig()->set($b['uid'], 'twitter', 'last_status', $status);
if ($key == 0) {
Worker::defer();
}
break;
}
@ -264,7 +298,7 @@ function twitter_post_status(int $uid, string $status, array $media_ids = [], st
return $response->data->id;
}
function twitter_upload_image(int $uid, array $image)
function twitter_upload_image(int $uid, array $image, int $retrial)
{
if (!empty($image['id'])) {
$photo = Photo::selectFirst([], ['id' => $image['id']]);
@ -274,14 +308,20 @@ function twitter_upload_image(int $uid, array $image)
$picturedata = Photo::getImageForPhoto($photo);
$type = Images::getMimeTypeByData($picturedata, $photo['filename'], $photo['type']);
$picture = Photo::resizeToFileSize(new Image($picturedata, $type), TWITTER_MAX_IMAGE_SIZE);
$picture = new Image($picturedata, $photo['type']);
$height = $picture->getHeight();
$width = $picture->getWidth();
$size = strlen($picturedata);
$picture = Photo::resizeToFileSize($picture, TWITTER_IMAGE_SIZE[$retrial]);
$new_height = $picture->getHeight();
$new_width = $picture->getWidth();
$picturedata = $picture->asString();
$new_size = strlen($picturedata);
Logger::info('Uploading', ['uid' => $uid, 'size' => strlen($picturedata), 'type' => @getimagesizefromstring($picturedata), 'photo' => $photo]);
Logger::info('Uploading', ['uid' => $uid, 'retrial' => $retrial, 'height' => $new_height, 'width' => $new_width, 'size' => $new_size, 'orig-height' => $height, 'orig-width' => $width, 'orig-size' => $size, 'image' => $image]);
$media = twitter_post($uid, 'https://upload.twitter.com/1.1/media/upload.json', 'form_params', ['media' => base64_encode($picturedata)]);
Logger::info('Uploading done', ['uid' => $uid, 'retrial' => $retrial, 'height' => $new_height, 'width' => $new_width, 'size' => $new_size, 'orig-height' => $height, 'orig-width' => $width, 'orig-size' => $size, 'image' => $image]);
if (isset($media->media_id_string)) {
$media_id = $media->media_id_string;
@ -322,8 +362,54 @@ function twitter_post(int $uid, string $url, string $type, array $data): stdClas
]);
$response = $client->post($url, ['auth' => 'oauth', $type => $data]);
$body = $response->getBody()->getContents();
$content = json_decode($response->getBody()->getContents()) ?? new stdClass;
$status = [
'code' => $response->getStatusCode(),
'reason' => $response->getReasonPhrase(),
'content' => $body
];
DI::pConfig()->set($uid, 'twitter', 'last_status', $status);
$content = json_decode($body) ?? new stdClass;
Logger::debug('Success', ['content' => $content]);
return $content;
}
function twitter_test_connection(int $uid)
{
$stack = HandlerStack::create();
$middleware = new Oauth1([
'consumer_key' => DI::pConfig()->get($uid, 'twitter', 'api_key'),
'consumer_secret' => DI::pConfig()->get($uid, 'twitter', 'api_secret'),
'token' => DI::pConfig()->get($uid, 'twitter', 'access_token'),
'token_secret' => DI::pConfig()->get($uid, 'twitter', 'access_secret'),
]);
$stack->push($middleware);
$client = new Client([
'handler' => $stack
]);
try {
$response = $client->get('https://api.twitter.com/2/users/me', ['auth' => 'oauth']);
$status = [
'code' => $response->getStatusCode(),
'reason' => $response->getReasonPhrase(),
'content' => $response->getBody()->getContents()
];
DI::pConfig()->set(1, 'twitter', 'last_status', $status);
Logger::info('Test successful', ['uid' => $uid]);
} catch (RequestException $exception) {
$status = [
'code' => $exception->getCode(),
'reason' => $exception->getResponse()->getReasonPhrase(),
'content' => $exception->getMessage()
];
DI::pConfig()->set(1, 'twitter', 'last_status', $status);
Logger::info('Test failed', ['uid' => $uid]);
}
}