-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
46 lines (38 loc) · 1.57 KB
/
run.php
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
41
42
43
44
45
46
<?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(sys_get_temp_dir() . '/X-ACCESS-TOKEN.txt');
$accessTokenSecret = file_get_contents(sys_get_temp_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);
$userInfo = $client->me();
echo "Hello, " . $userInfo['data']['name'] . "!\n";
// 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');
// Single post example
$post = new X();
$post->set('apiKey', $apiKey);
$post->set('apiKeySecret', $apiKeySecret);
$post->set('accessToken', $accessToken);
$post->set('accessTokenSecret', $accessTokenSecret);
$post->post($threadPartA);
// Thread post exmple
$threadPoster = new X();
$threadPoster->set('apiKey', $apiKey);
$threadPoster->set('apiKeySecret', $apiKeySecret);
$threadPoster->set('accessToken', $accessToken);
$threadPoster->set('accessTokenSecret', $accessTokenSecret);
$thread = [$threadPartA, $threadPartB];
$threadPoster->post($thread);
echo "Thread posted successfully!\n";