Esempio n. 1
0
    $access_token = $oauth_pecl->getAccessToken(Imgur::$oauth1a_access_token_url);
    // Replace the user's request token with their access token.
    // This is the *ACCESS* Token and Secret.  You should store these in your
    // database with the user's record.  We're putting them in the session only
    // so the demo will work.
    $prev_token = $_SESSION['token'];
    $_SESSION['token'] = $access_token['oauth_token'];
    $_SESSION['token_secret'] = $access_token['oauth_token_secret'];
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret']) && $_SESSION['token'] != $prev_token) {
        echo "Step 8: Success!  Your final access token is {$_SESSION['token']}.  ";
        echo "We can now proceed to step nine.  ";
        echo '<a href="', $_SERVER['PHP_SELF'], '">Clicky.</a>';
        $_SESSION['oauth_state'] = 2;
    } else {
        echo "Something went wrong.  Didn't get the right tokens.  You should probably see an error message above.<br>";
        echo "Be aware that these tokens are one-use only.  You <i>might</i> need to reset your session.";
    }
    exit;
} elseif ($_SESSION['oauth_state'] == 2) {
    echo "Step 9: You should have access with key {$_SESSION['token']}!<br>";
    // Just like in the previous state, we need to update the object with the
    // current token+secret pair.
    $oauth_pecl->setToken($_SESSION['token'], $_SESSION['token_secret']);
    // And, off we go, setOAuth detects the class and does the right thing.
    Imgur::setOAuth($oauth_pecl);
    // We'll fall through at this point, so the demo in oauth.php can run.
    echo "Done!  We can make make OAuth requests on your behalf.<br><hr>";
} else {
    echo "Whoa, your OAuth state is totally bogus, dude.";
    exit;
}
Esempio n. 2
0
    // This is the *ACCESS* Token and Secret.  You should store these in your
    // database with the user's record.  We're putting them in the session only
    // so the demo will work.
    $prev_token = $_SESSION['token'];
    $_SESSION['token'] = $access_token->getToken();
    $_SESSION['token_secret'] = $access_token->getTokenSecret();
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret']) && $_SESSION['token'] != $prev_token) {
        echo "Step 8: Success!  Your final access token is {$_SESSION['token']}.  ";
        echo "We can now proceed to step nine.  ";
        echo '<a href="', $_SERVER['PHP_SELF'], '">Clicky.</a>';
        $_SESSION['oauth_state'] = 2;
    } else {
        echo "Something went wrong.  Didn't get the right tokens.  You should probably see an error message above.<br>";
        echo "Be aware that these tokens are one-use only.  You <i>might</i> need to reset your session.";
    }
    exit;
} elseif ($_SESSION['oauth_state'] == 2) {
    echo "Step 9: You should have access with key {$_SESSION['token']}!<br>";
    // Once again, this is why they have you serialize it in their example code...
    $access_token = new Zend_Oauth_Token_Access();
    $access_token->setToken($_SESSION['token']);
    $access_token->setTokenSecret($_SESSION['token_secret']);
    // setOAuth wants to work only with the result of this call, which will be
    // a Zend_Oauth_Client, a subclass of Zend_Http_Client.
    Imgur::setOAuth($access_token->getHttpClient($zend_oauth_config));
    // We'll fall through at this point, so the demo in oauth.php can run.
    echo "Done!  We can make make OAuth requests on your behalf.<br><hr>";
} else {
    echo "Whoa, your OAuth state is totally bogus, dude.";
    exit;
}
Esempio n. 3
0
    // This can probably throw a variety of exceptions as well, but I haven't
    // encountered any of them.  Also note the express passing of oauth_verifier here.
    $oauth_pear->getAccessToken(Imgur::$oauth1a_access_token_url, array_key_exists('oauth_verifier', $_REQUEST) ? $_REQUEST['oauth_verifier'] : null);
    // This is the *ACCESS* Token and Secret.  You should store these in your
    // database with the user's record.  We're putting them in the session only
    // so the demo will work.  It's worth noting again that on subsequent pageviews,
    // the new Access Token & Secret are automatically passed into the OAuth Consumer.
    $prev_token = $_SESSION['token'];
    $_SESSION['token'] = $oauth_pear->getToken();
    $_SESSION['token_secret'] = $oauth_pear->getTokenSecret();
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret']) && $_SESSION['token'] != $prev_token) {
        echo "Step 8: Success!  Your final access token is {$_SESSION['token']}.  ";
        echo "We can now proceed to step nine.  ";
        echo '<a href="', $_SERVER['PHP_SELF'], '">Clicky.</a>';
        $_SESSION['oauth_state'] = 2;
    } else {
        echo "Something went wrong.  Didn't get the right tokens.  You should probably see an error message above.<br>";
        echo "Be aware that these tokens are one-use only.  You <i>might</i> need to reset your session.";
    }
    exit;
} elseif ($_SESSION['oauth_state'] == 2) {
    echo "Step 9: You should have access with key {$_SESSION['token']}!<br>";
    // setOAuth will detect the type of object and automatically load the proper
    // HTTP adapter, so we don't need to do any special work.
    Imgur::setOAuth($oauth_pear);
    // We'll fall through at this point, so the demo in oauth.php can run.
    echo "Done!  We can make make OAuth requests on your behalf.<br><hr>";
} else {
    echo "Whoa, your OAuth state is totally bogus, dude.";
    exit;
}