Ejemplo n.º 1
0
function checkAuthResult()
{
    $oauthToken = getVariable('oauth_token', FALSE);
    $oauthVerifier = getVariable('oauth_verifier', FALSE);
    /** @var \AABTest\OauthRequestToken $oauthRequest */
    $oauthRequest = getSessionVariable('oauthRequest', null);
    if (!$oauthToken || !$oauthVerifier || !$oauthRequest) {
        return;
    }
    if ($oauthToken != $oauthRequest->oauthToken) {
        //Miss-match on what we're tring to validated.
        return;
    }
    try {
        $oauthConfig = new OauthConfig(FLICKR_KEY, FLICKR_SECRET);
        $oauthService = new \ArtaxApiBuilder\Service\FlickrOauth1($oauthConfig);
        $oauthService->setOauthToken($oauthRequest->oauthToken);
        $oauthService->setTokenSecret($oauthRequest->oauthTokenSecret);
        $api = new \AABTest\FlickrAPI\FlickrAPI(FLICKR_KEY, $oauthService);
        $command = $api->GetOauthAccessToken($oauthVerifier);
        $oauthAccessToken = $command->execute();
        setSessionVariable('oauthAccessToken', $oauthAccessToken);
        echo "Oauth is confirmed - username is:" . $oauthAccessToken->user->username;
    } catch (\AABTest\FlickrAPI\FlickrAPIException $fae) {
        echo "Exception processing response: " . $fae->getResponse()->getBody();
    }
}
Ejemplo n.º 2
0
function createOauthRequest()
{
    $oauthConfig = new OauthConfig(FLICKR_KEY, FLICKR_SECRET);
    try {
        $oauthService = new \ArtaxApiBuilder\Service\FlickrOauth1($oauthConfig);
        $api = new \AABTest\FlickrAPI\FlickrAPI(FLICKR_KEY, $oauthService);
        $command = $api->GetOauthRequestToken("http://localhost:8000/flickr/return.php");
        $oauthRequest = $command->execute();
        setSessionVariable('oauthRequest', $oauthRequest);
        $flickrURL = "http://www.flickr.com/services/oauth/authorize?oauth_token=" . $oauthRequest->oauthToken;
        echo sprintf("Please click <a href='%s'>here to auth</a>. ", $flickrURL);
    } catch (\AABTest\FlickrAPI\FlickrAPIException $fae) {
        echo "FlickrAPIException response body.";
        var_dump($fae->getResponse()->getBody());
    }
}