-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexample.php
More file actions
70 lines (61 loc) · 2.68 KB
/
example.php
File metadata and controls
70 lines (61 loc) · 2.68 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
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
<?php
/**
* Authentication library for Upwork API using OAuth 2.0
* Example: authenticate and send a test request to the protected resource
*
* @final
* @package UpworkAPI
* @since 03/02/2018
* @copyright Copyright 2018(c) Upwork.com
* @author Maksym Novozhylov <mnovozhilov@upwork.com>
* @license Upwork's API Terms of Use {@link https://developers.upwork.com/api-tos.html}
*/
require __DIR__ . '/vendor/autoload.php';
// if you already have the tokens, they can be read from session
// or other secure storage
//$_SESSION['access_token'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
//$_SESSION['access_secret']= 'xxxxxxxxxxxx';
$config = new \Upwork\API\Config(
array(
'clientId' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', // SETUP YOUR CONSUMER KEY
'clientSecret' => 'xxxxxxxxxxxx', // SETUP KEY SECRET
//'grantType' => 'client_credentials', // used in Client Credentials Grant
'redirectUri' => 'https://a.callback.url/', // used in Code Authorization Grant
'accessToken' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', // WARNING: keep this up-to-date!
'refreshToken' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', // WARNING: keep this up-to-date! // NOT needed for Client Credentials Grant
'expiresIn' => 'xxxxxxxxxx', // WARNING: keep this up-to-date!
//'debug' => true, // enables debug mode
//'authType' => 'MyOAuthPHPLib' // your own authentication type, see AuthTypes directory
)
);
$client = new \Upwork\API\Client($config);
//$client::setOrgUidHeader('1234567890'); // Organization UID (optional)
// $accessTokenInfo has the following structure
// array('access_token' => ..., 'refresh_token' => ..., 'expires_in' => ...);
// keeps the access token in a secure place
// gets info of authenticated user
$accessTokenInfo = $client->auth();
// WARNING: auth() will refresh the tokens for you but you need to check if the token was refreshed
// and replace the old access/refresh token pair with a new one in your security data storage.
// if needed, it is possible to access library instance
// using $client->getServer()->getInstance()->...;
// e.g. "if ($client->getServer()->getInstance()->getToken() == 'current-token') { ... }"
// for instance, for web-based applications you may need to get
// and safe 'state' in the session to be able to compare it later
// and prevent a CSRF attack
// "if ($client->getServer()->getInstance()->getState() != 'my-saved-state') { ... }"
$graphql = new \Upwork\API\Routers\Graphql($client);
$params['query'] = <<<QUERY
query {
user {
id
nid
rid
}
organization {
id
}
}
QUERY;
$data = $graphql->execute($params);
print_r($data);