-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample1.php
55 lines (42 loc) · 1.63 KB
/
example1.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
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Acc
$accessTokensApi = new URLR\Api\AccessTokensApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client()
);
$accessTokensRequest = new \URLR\Model\AccessTokensRequest([
'username' => '',
'password' => '',
]); // \URLR\Model\AccessTokensRequest | Your credentials
try {
$token = $accessTokensApi->create_access_token($accessTokensRequest)->getToken();
} catch (Exception $e) {
echo 'Exception when calling AccessTokensApi->create_access_token: ', $e->getMessage(), PHP_EOL;
exit;
}
$config = URLR\Configuration::getDefaultConfiguration()->setAccessToken($token);
// Link shortening
$linksApi = new URLR\Api\LinksApi(null, $config);
$createLinkRequest = new \URLR\Model\CreateLinkRequest([
'url' => '',
'teamId' => ''
]); // \URLR\Model\CreateLinkRequest | Infos of the link to shorten
try {
$result = $apiInstance->createLink($createLinkRequest);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling LinksApi->createLink: ', $e->getMessage(), PHP_EOL;
}
// Statistics
$apiInstance = new URLR\Api\StatisticsApi(null, $config);
$statisticsRequest = new \URLR\Model\StatisticsRequest([
'linkId' => ''
]); // \URLR\Model\StatisticsRequest | Infos to provide to get statistics of a link
try {
$result = $apiInstance->statistics($statisticsRequest);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling StatisticsApi->statistics: ', $e->getMessage(), PHP_EOL;
}