-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.php
More file actions
40 lines (31 loc) · 1.32 KB
/
run.php
File metadata and controls
40 lines (31 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require 'vendor/autoload.php';
$apiKey = file_get_contents(realpath(__DIR__ . '/../../') . '/X-API-KEY.txt');
$apiKeySecret = file_get_contents(realpath(__DIR__ . '/../../') . '/X-API-KEY-SECRET.txt');
$accessToken = file_get_contents(realpath(__DIR__ . '/../../') . '/X-ACCESS-TOKEN.txt');
$accessTokenSecret = file_get_contents(realpath(__DIR__ . '/../../') . '/X-ACCESS-TOKEN-SECRET.txt');
use codechap\x\X;
use codechap\x\Msg;
$client = new X();
$client->set('apiKey', $apiKey);
$client->set('apiKeySecret', $apiKeySecret);
$client->set('accessToken', $accessToken);
$client->set('accessTokenSecret', $accessTokenSecret);
// Get user info
$userInfo = $client->me();
echo "Hello, " . $userInfo['data']['name'] . "!\n";
// Single post with image and alt text
$msg = new Msg();
$msg->set('content', 'Hello, X!');
$msg->set('image', 'img-HrW6drkAzh4UqUaXD3o3H.jpeg');
$msg->set('altText', 'A sample image');
$client->post($msg);
echo "Single post successful!\n";
// Thread example
$threadPartA = new Msg();
$threadPartA->set('content', 'Hello, X! This is the first message.');
$threadPartA->set('image', 'img-HrW6drkAzh4UqUaXD3o3H.jpeg');
$threadPartB = new Msg();
$threadPartB->set('content', 'Hello, X! This is the second message.');
$client->post([$threadPartA, $threadPartB]);
echo "Thread posted successfully!\n";