-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_api.php
127 lines (115 loc) · 3.6 KB
/
test_api.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Test Mastodon API.
*
* Make a copy of .env.example to .env
* and define the values obtained with
* test_oauth.php + your Mastodon email and password.
*/
require __DIR__ . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$name = 'MyMastodonApp';
$instance = 'mastodon.social';
$oAuth = new Colorfield\Mastodon\MastodonOAuth($name, $instance);
$oAuth->config->setClientId($_ENV['CLIENT_ID']);
$oAuth->config->setClientSecret($_ENV['CLIENT_SECRET']);
$oAuth->config->setBearer($_ENV['BEARER']);
$oAuth->config->setScopes(['read', 'write']);
$mastodonAPI = new Colorfield\Mastodon\MastodonAPI($oAuth->config);
$login = $oAuth->authenticateUser($_ENV['MASTODON_EMAIL'], $_ENV['MASTODON_PASSWORD']);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Test Mastodon API | API methods</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"
rel="stylesheet">
<style type="text/css">
body {
padding-top: 2rem;
padding-bottom: 2rem;
}
h3 {
margin-top: 2rem;
}
.row {
margin-bottom: 1rem;
}
.row .row {
margin-top: 1rem;
margin-bottom: 0;
}
[class*="col-"] {
padding-top: 1rem;
padding-bottom: 1rem;
background-color: rgba(86, 61, 124, .15);
border: 1px solid rgba(86, 61, 124, .2);
}
hr {
margin-top: 2rem;
margin-bottom: 2rem;
}
</style>
</head>
<body>
<div class="container">
<h1>Test Mastodon API</h1>
<h2>Get</h2>
<div class="row">
<div class="col-md-4"><code>/accounts/verify_credentials</code></div>
<div class="col-md-8">
<?php
$credentials = $mastodonAPI->get('/accounts/verify_credentials');
$user = new Colorfield\Mastodon\UserVO($credentials);
var_dump($credentials);
?>
</div>
</div>
<div class="row">
<div class="col-md-4"><code>/accounts/USER_ID/followers</code></div>
<div class="col-md-8">
<?php
$followers = $mastodonAPI->get('/accounts/' . $user->id . '/followers');
var_dump($followers);
?>
</div>
</div>
<div class="row">
<div class="col-md-4"><code>/accounts/search</code> <p>q='color', limit=10</p></div>
<div class="col-md-8">
<?php
$search = $mastodonAPI->get('/accounts/search', ['q' => 'colorfield', 'limit' => 10,]);
var_dump($search);
?>
</div>
</div>
<h2>Post</h2>
<div class="row">
<div class="col-md-4"><code>/notifications/clear</code></div>
<div class="col-md-8">
<?php
$clearedNotifications = $mastodonAPI->post('/notifications/clear');
var_dump($clearedNotifications);
?>
</div>
</div>
<div class="row">
<div class="col-md-4"><code>/follows</code><p>uri='[email protected]'</p></div>
<div class="col-md-8">
<p>Your token should cover the 'follow' scope for this.</p>
<?php
//$followed = $mastodonAPI->post('/follows');
//var_dump($followed);
?>
</div>
</div>
</div> <!-- /container -->
</body>
</html>