OAuth回调进入循环

I'm trying to authenticate my application with the ETrade API using OAuth. After I redirect the browser to ETrade for the user to authenticate, the callback URL is the same page the user started with (I go back to the same page in order to finish off the authentication). However, once it's redirected back to the same page, the redirect to ETrade happens again. How would I do this so the app isn't redirected but rather can finish off the authentication? Thanks!

PHP:

require_once("./autotrading/SDK/samples/config.php");
require_once("./autotrading/SDK/Common/common.php");    
  $key = ETWS_APP_KEY;
  $secret = ETWS_APP_SECRET;

  $consumer = new etOAuthConsumer($key, $secret); 
  $request = new etOAuth($consumer);

  $req_token = $request->GetRequestToken(); 
  $oauthToken = $req_token['oauth_token'];
  $oauthSecret = $req_token['oauth_token_secret'];
  $authURL = $request->GetAuthorizeURL(); 
  header('Location: '.$authURL);
//after authenticating, etrade's callback url looks like this: http://yourdomain.com/index.php?oauth_token=abc&oauth_verifier=123
if(isset($_GET['oauth_verifier'])) {
  $verifierCode = trim($_GET['oauth_verifier']);
  echo $verifierCode;
  $accessCode = GetAccessToken($verifierCode);
}

For reference, here's the API: https://developer.etrade.com/ctnt/dev-portal/getContent?contentUri=V0_Code-SDKGuides-PHP

If your callback with etrade is configured properly, you should be getting oauth_verifier in the query string.

You should be able to trap that oauth_verifier query string element exists and has a value.

Look at page 16 of the etrade PDF concerning their API.

The problem is when the callback comes and runs this it never reaches your if statment at the end because you have a header being set. Try this...

if(isset($_GET['oauth_verifier'])) {
  $verifierCode = trim($_GET['oauth_verifier']);
  echo $verifierCode;
  $accessCode = GetAccessToken($verifierCode);
}else{
  header('Location: '.$authURL); 
}