Пример #1
0
<?php

/**
 * Authentication library for Upwork API using OAuth
 *
 * @final
 * @package     UpworkAPI
 * @since       04/21/2014
 * @copyright   Copyright 2014(c) Upwork.com
 * @author      Maksym Novozhylov <*****@*****.**>
 * @license     Upwork's API Terms of Use {@link https://developers.upwork.com/api-tos.html}
 */
session_start();
require __DIR__ . '/vendor/autoload.php';
$config = new \Upwork\API\Config(array('consumerKey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'consumerSecret' => 'xxxxxxxxxxxxx', 'accessToken' => $_SESSION['access_token'], 'accessSecret' => $_SESSION['access_secret'], 'requestToken' => $_SESSION['request_token'], 'requestSecret' => $_SESSION['request_secret'], 'verifier' => $_GET['oauth_verifier'], 'mode' => 'web'));
$client = new \Upwork\API\Client($config);
if (empty($_SESSION['request_token']) && empty($_SESSION['access_token'])) {
    // we need to get and save the request token. It will be used again
    // after the redirect from the Upwork site
    $requestTokenInfo = $client->getRequestToken();
    $_SESSION['request_token'] = $requestTokenInfo['oauth_token'];
    $_SESSION['request_secret'] = $requestTokenInfo['oauth_token_secret'];
    // request authorization
    $client->auth();
} elseif (empty($_SESSION['access_token'])) {
    // the callback request should be pointed to this script as well as
    // the request access token after the callback
    $accessTokenInfo = $client->auth();
    $_SESSION['access_token'] = $accessTokenInfo['access_token'];
    $_SESSION['access_secret'] = $accessTokenInfo['access_secret'];
}
Пример #2
0
 * Authentication library for Upwork API using OAuth
 *
 * @final
 * @package     UpworkAPI
 * @since       04/21/2014
 * @copyright   Copyright 2014(c) Upwork.com
 * @author      Maksym Novozhylov <*****@*****.**>
 * @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('consumerKey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'consumerSecret' => 'xxxxxxxxxxxxxx', 'accessToken' => $_SESSION['access_token'], 'accessSecret' => $_SESSION['access_secret'], 'debug' => true));
$client = new \Upwork\API\Client($config);
$accessTokenInfo = $client->auth();
// $accessTokenInfo has the following structure
// array('access_token' => ..., 'access_secret' => ...);
// keeps the access token in a secure place
// gets a list of trays for the authenticated user
$mc = new \Upwork\API\Routers\Mc($client);
$trays = $mc->getTrays();
print_r($trays);
// gets info of the authenticated user
$auth = new \Upwork\API\Routers\Auth($client);
$info = $auth->getUserInfo();
print_r($info);
// attempts to start a new message thread with wrong parameters
// to test an error response from the server (the subject is missing)
$params = array('recipients' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'body' => 'this is a test message from Upwork Library');
Пример #3
0
 * Example: using your own authentication OAuth client
 *
 * @final
 * @package     UpworkAPI
 * @since       05/20/2014
 * @copyright   Copyright 2014(c) Upwork.com
 * @author      Maksym Novozhylov <*****@*****.**>
 * @license     Upwork's API Terms of Use {@link https://developers.upwork.com/api-tos.html}
 */
// Our php-oauth library - used in this example - requires a session
session_start();
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('consumerKey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', 'consumerSecret' => 'xxxxxxxxxxxx', 'accessToken' => $_SESSION['access_token'], 'accessSecret' => $_SESSION['access_secret'], 'debug' => true, 'authType' => 'OAuthPHPLib'));
$client = new \Upwork\API\Client($config);
// our example AuthType allows assigning already known token data
if (!empty($_SESSION['access_token']) && !empty($_SESSION['access_secret'])) {
    $client->getServer()->getInstance()->addServerToken($config::get('consumerKey'), 'access', $_SESSION['access_token'], $_SESSION['access_secret'], 0);
} else {
    // $accessTokenInfo has the following structure
    // array('access_token' => ..., 'access_secret' => ...);
    // keeps the access token in a secure place
    // gets info of authenticated user
    $accessTokenInfo = $client->auth();
}
$auth = new \Upwork\API\Routers\Auth($client);
$info = $auth->getUserInfo();
print_r($info);