Esempio n. 1
0
        $_SESSION['SmugGalReqToken'] = serialize($request_token);
        // Step 2: Get the User to login to SmugMug and authorise this demo
        echo '<p>Click <a href="' . $client->getAuthorizeURL() . '"><strong>HERE</strong></a> to Authorize This Demo.</p>';
        // Alternatively, automatically direct your visitor by commenting out the above line in favour of this:
        //header("Location:".$client->getAuthorizeURL());
    } else {
        $reqToken = unserialize($_SESSION['SmugGalReqToken']);
        unset($_SESSION['SmugGalReqToken']);
        // Step 3: Use the Request token obtained in step 1 to get an access token
        $client->setToken($reqToken['oauth_token'], $reqToken['oauth_token_secret']);
        $oauth_verifier = $_GET['oauth_verifier'];
        // This comes back with the callback request.
        $token = $client->getAccessToken($oauth_verifier);
        // The results of this call is what your application needs to store.
        // Get the username of the authenticated user
        $username = $client->get('!authuser')->User->NickName;
        // Get the first public album
        $albums = $client->get("user/{$username}!albums", array('count' => 1));
        // Get the first 25 photos in the album
        $images = $client->get($albums->Album[0]->Uris->AlbumImages, array('count' => 25));
        // Display the image thumbnails.
        foreach ($images->AlbumImage as $image) {
            printf('<a href="%s"><img src="%s" title="%s" alt="%s" width="150" height="150" /></a>', $image->WebUri, $image->ThumbnailUrl, $image->Title, $image->ImageKey);
        }
    }
} catch (Exception $e) {
    echo "{$e->getMessage()} (Error Code: {$e->getCode()})";
}
?>
    </div>
</body>
Esempio n. 2
0
    <style type="text/css">
        body { background-color: #fff; color: #444; font-family: sans-serif; }
        div { width: 750px; margin: 0 auto; text-align: center; }
        img { border: 0;}
    </style>
</head>
<body>
    <div>
        <a href="http://phpsmug.com"><img src="phpSmug-logo.svg" /></a>
        <h2>phpSmug First Album Example</h2>
<?php 
require_once 'vendor/autoload.php';
try {
    $options = ['AppName' => $AppName, '_verbosity' => 1];
    $client = new phpSmug\Client($APIKey, $options);
    // Get the first public album
    $albums = $client->get("user/{$username}!albums", array('count' => 1));
    // Get the first 25 photos in the album
    $images = $client->get($albums->Album[0]->Uris->AlbumImages, array('count' => 25));
    // Display the image thumbnails.
    foreach ($images->AlbumImage as $image) {
        printf('<a href="%s"><img src="%s" title="%s" alt="%s" width="150" height="150" /></a>', $image->WebUri, $image->ThumbnailUrl, $image->Title, $image->ImageKey);
    }
} catch (Exception $e) {
    printf('%s (Error Code: %d)', $e->getMessage(), $e->getCode());
}
?>
    </div>
</body>
</html>