/**
  * Implements section 6.3 of the OAuth spec.
  */
 private function exchangeRequestToken(RemoteContentRequest $request)
 {
     try {
         $accessor = $this->accessorInfo->getAccessor();
         $url = $accessor->consumer->callback_url->accessTokenURL;
         $msgParams = array();
         $msgParams[ShindigOAuth::$OAUTH_TOKEN] = $accessor->requestToken;
         self::addIdentityParams($msgParams, $request->getToken());
         $callbackUrl = $this->requestParams->getReceivedCallback();
         if (strlen($callbackUrl) > 0) {
             $parsed_url = parse_url($callbackUrl);
             parse_str($parsed_url["query"], $url_params);
             if (strlen($url_params["oauth_token"]) > 0 && strlen($url_params["oauth_verifier"]) > 0 && $url_params["oauth_token"] == $accessor->requestToken) {
                 $msgParams[ShindigOAuth::$OAUTH_VERIFIER] = $url_params["oauth_verifier"];
             } else {
                 throw new GadgetException("Invalid received callback URL: " . $callbackUrl);
             }
         }
         $request = $this->newRequestMessageParams($url->url, $msgParams);
         $reply = $this->sendOAuthMessage($request);
         $reply->requireParameters(array(ShindigOAuth::$OAUTH_TOKEN, ShindigOAuth::$OAUTH_TOKEN_SECRET));
         $accessor->accessToken = $reply->get_parameter(ShindigOAuth::$OAUTH_TOKEN);
         $accessor->tokenSecret = $reply->get_parameter(ShindigOAuth::$OAUTH_TOKEN_SECRET);
     } catch (Exception $e) {
         // It's unfortunate the OAuth libraries throw a generic Exception.
         throw new GadgetException("INTERNAL SERVER ERROR: " . $e);
     }
 }