getRequestToken($request_url, $callback_url); /* Store the secret as we'll need it to fetch the authorized token, if and when the member allows it. */ $_SESSION['secret'] = $token_info['oauth_token_secret']; /* Redirect the member's browser to the token authorization page. This helps to ensure that the member is in control of granting or revoking API access to us on her behalf. */ header('Location: ' . $authorize_url . '/?oauth_token=' . $token_info['oauth_token']); /* Exit immediately as we're redirecting the member. This also ensures that the session cookie is sent which preserves our session for when the member returns (and when that happens we'll need the "secret" that we stored). */ exit(0); } else { /* Home stretch! We have an 'oauth_verifier' parameter which should mean that the member has granted us permission. Yay! Now we must use the secret we stored in the session along with the verification token we just received (as the value of the 'oauth_verifier' parameter) to authorize our token. The 'secret' is a way of securely tying the unauthorized token to the verification token, which represents the member granting us authority and ultimatley authorizes our perviously unauthorized token. */ $oauth->setToken($_GET['oauth_token'], $_SESSION['secret']); $token_info = $oauth->getAccessToken($access_url, '', $_GET['oauth_verifier']); /* We should finally have our authorized oauth token and secret which we can store and use to make authorized API calls on behalf of the authorizing member. The token and its secret are available as values in the $token_info associatve array as $token_info['oauth_token'] and $token_info['oauth_token_secret'], respectively. For an example of using these values, see: https://gist.github.com/chrislewis/4465cd864c8f35a71cfd. */ } ?>