函数中的Que API调用

  • 本文关键字:API 调用 Que 函数 php
  • 更新时间 :
  • 英文 :


我正在对API进行两次调用。这两个调用唯一不同的地方是URL。我基本上想知道的是,我如何才能更好地构建它?也许在一个que里让他们互相追?有时第二个调用返回一个"0";临界误差";在Wordpress页面上调用。

有什么建议吗?

private $oauth_Key = 'xxx';
private $oauth_consumer = 'xxx';
private $api_url = 'xxx';
private $cat_url = 'xxx';
try {
$oauth = new OAuth($this->oauth_Key, $this->oauth_consumer, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->fetch($this->api_url);
$response_info = $oauth->getLastResponseInfo();
header("Content-Type: {$response_info["content_type"]}");
$res = $oauth->getLastResponse();
$oauth2 = new OAuth($this->oauth_Key, $this->oauth_consumer, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oaut2->fetch($this->cat_url);
$response_info2 = $oauth2->getLastResponseInfo();
header("Content-Type: {$response_info2["content_type"]}");
$res2 = $oauth2->getLastResponse();
} catch(OAuthException $e) {
echo "Exception caught!n";
echo "Response: ". $e->lastResponse . "n";
}

刚刚想好了。对代码进行了一点重新构造。见下文:

private $oauth_Key = 'xxx';
private $oauth_consumer = 'xxx';
private $api_url = 'xxx';
private $cat_url = 'xxx';
try {
$oauth = new OAuth($this->oauth_Key, $this->oauth_consumer, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->fetch($this->api_url);
$response_info = $oauth->getLastResponseInfo();
header("Content-Type: {$response_info["content_type"]}");
$res = $oauth->getLastResponse();
$oauth2 = new OAuth($this->oauth_Key, $this->oauth_consumer, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth2->fetch($this->cat_url);
$response_info2 = $oauth2->getLastResponseInfo();
header("Content-Type: {$response_info2["content_type"]}");
$res2 = $oauth2->getLastResponse();
} catch(OAuthException $e) {
echo "Exception caught!n";
echo "Response: ". $e->lastResponse . "n";
}

最新更新