Issues (144)

examples/provider/scoopit.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * Example of making API calls for the ScoopIt service.
5
 *
6
 * @author     Pieter Hordijk <[email protected]>
7
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
8
 */
9
10
use OAuth\Common\Consumer\Credentials;
11
use OAuth\Common\Storage\Session;
12
use OAuth\OAuth1\Service\ScoopIt;
13
14
/**
15
 * Bootstrap the example.
16
 */
17
require_once __DIR__ . '/bootstrap.php';
18
19
// Session storage
20
$storage = new Session();
21
22
// Setup the credentials for the requests
23
$credentials = new Credentials(
24
    $servicesCredentials['scoopit']['key'],
25
    $servicesCredentials['scoopit']['secret'],
26
    $currentUri->getAbsoluteUri()
27
);
28
29
// Instantiate the ScoopIt service using the credentials, http client and storage mechanism for the token
30
$scoopItService = $serviceFactory->createService('ScoopIt', $credentials, $storage);
31
32
if (!empty($_GET['oauth_token'])) {
33
    $token = $storage->retrieveAccessToken('ScoopIt');
34
35
    // This was a callback request from ScoopIt, get the token
36
    $scoopItService->requestAccessToken(
37
        $_GET['oauth_token'],
38
        $_GET['oauth_verifier'],
39
        $token->getRequestTokenSecret()
40
    );
41
42
    // Send a request now that we have access token
43
    $result = json_decode($scoopItService->request('profile'));
44
45
    echo 'result: <pre>' . print_r($result, true) . '</pre>';
0 ignored issues
show
Are you sure print_r($result, true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
    echo 'result: <pre>' . /** @scrutinizer ignore-type */ print_r($result, true) . '</pre>';
Loading history...
46
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
47
    // extra request needed for oauth1 to request a request token :-)
48
    $token = $scoopItService->requestRequestToken();
49
50
    $url = $scoopItService->getAuthorizationUri(['oauth_token' => $token->getRequestToken()]);
51
    header('Location: ' . $url);
52
} else {
53
    $url = $currentUri->getRelativeUri() . '?go=go';
54
    echo "<a href='$url'>Login with ScoopIt!</a>";
55
}
56