Skip to content
/ x Public

A simple PHP library for posting to X (Twitter) using API v2.

License

Notifications You must be signed in to change notification settings

codeChap/x

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP X (Everything App) API Post Library

A simple PHP library for posting to X (Formerly Twitter) using the free tier.

Installation

composer require codechap/x:dev-master

Example

<?php

require 'vendor/autoload.php';

use codechap\x\X;
use codechap\x\Msg;

// Create thread messages
$threadPartA = new Msg();
$threadPartA->set('content', 'Hello, X!');
$threadPartA->set('image', 'img-HrW6drkAzh4UqUaXD3o3H.jpeg');

$threadPartB = new Msg();
$threadPartB->set('content', 'Hello, X! This is the second message.');
$threadPartB->set('image', 'img-HrW6drkAzh4UqUaXD3o3H.jpeg');

// Initialize X client for thread
$threadPoster = new X();
$threadPoster->set('apiKey', $apiKey);
$threadPoster->set('apiKeySecret', $apiKeySecret);
$threadPoster->set('accessToken', $accessToken);
$threadPoster->set('accessTokenSecret', $accessTokenSecret);

// Post thread
$thread = [$threadPartA, $threadPartB];
$threadPoster->post($thread);
echo "Thread posted successfully!\n";
<?php

require 'vendor/autoload.php';

use codechap\x\X;
use codechap\x\Msg;

// Single post example
$post = new X();
$post->set('apiKey', $apiKey);
$post->set('apiKeySecret', $apiKeySecret);
$post->set('accessToken', $accessToken);
$post->set('accessTokenSecret', $accessTokenSecret);

$msg = new Msg();
$msg->set('content', 'Hello, X!');
$msg->set('image', 'img-HrW6drkAzh4UqUaXD3o3H.jpeg');

$post->post($msg);
echo "Single post successful!";
<?php

require 'vendor/autoload.php';

use codechap\x\X;

// Get your user info
$client = new X();
$client->set('apiKey', $apiKey);
$client->set('apiKeySecret', $apiKeySecret);
$client->set('accessToken', $accessToken);
$client->set('accessTokenSecret', $accessTokenSecret);
$userInfo = $client->me();
echo "Hello, " . $userInfo['data']['name'] . "!\n";

About

A simple PHP library for posting to X (Twitter) using API v2.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages