我遇到了这个问题,我不知道是否有人可以提供帮助。我在获取我认为的 oAuth 密钥时遇到问题。我不断返回的错误是 inValidKey ,我已经研究过。也许我只是不明白,但我似乎无法固定这个。
<?php
class ApiClient {
private $oauthToken;
public function __construct($oauthToken) {
$this->oauthToken = $oauthToken;
}
public function post($url, $data) {
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_TIMEOUT, '10');
$headers = array(
"Content-Type: application/json",
"Accept: application/json",
"Authorization: OAuth oauth_token={$this->oauthToken}",
"Content-Length: " . strlen($data_string)
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$ret = curl_exec($ch);
return json_decode($ret);
}
public function get($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '10');
$headers = array(
"Content-Type: application/json",
"Accept: application/json",
"Authorization: OAuth oauth_token={$this->oauthToken}"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$ret = curl_exec($ch);
return json_decode($ret);
}
}
class Webinar {
private $developerKey;
private $organizerKey;
protected $client;
// ##########################
private $apps = array(
'MMT' => array(
'developerKey' => '#######################3',
'oauthToken' => '',
'organizerKey' => '')
);
public function __construct($app = 'MMT') {
if(!array_key_exists($app, $this->apps)) {
throw new Exception('Invalid argument: unknown developer key');
}
$this->developerKey = $this->apps[$app]['developerKey'];
$this->organizerKey = $this->apps[$app]['organizerKey'];
$this->client = new ApiClient($this->apps[$app]['oauthToken']);
}
public function getUpcoming() {
return $this->client->get("https://api.citrixonline.com/G2W/rest/organizers/{$this->organizerKey}/upcomingWebinars");
}
public function getHistorical() {
return $this->client->get("https://api.citrixonline.com/G2W/rest/organizers/{$this->organizerKey}/historicalWebinars");
}
public function addRegistrant($webinarKey, $email, $firstname, $lastname) {
$url = "https://api.citrixonline.com/G2W/rest/organizers/{$this->organizerKey}/webinars/{$webinarKey}/registrants";
$data = (object) array(
'firstName' => $firstname,
'lastName' => $lastname,
'email' => $email
);
return $this->client->post($url, $data);
}
}
//****************************************************
$api = new Webinar();
print_r($api->getUpcoming));
?>