Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhanjun committed Sep 13, 2024
1 parent 6ce8c1b commit 056ef4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"AmazonAdsApi\\": "src/"
}
},
"version": "1.0.1",
"version": "1.0.2",
"require": {
"ext-curl": "*",
"ext-json": "*",
Expand Down
42 changes: 3 additions & 39 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,51 +142,15 @@ public function setDebug(bool $debug = false)
$this->debug = $debug;
}


/**
* @return array
* @throws Exception
*/
public function doRefreshToken(): array
public function doRefreshToken($refresh_token)
{
$headers = array(
'Content-Type: application/x-www-form-urlencoded;charset=UTF-8',
"User-Agent: $this->userAgent"
);

$refresh_token = rawurldecode($this->config['refreshToken']);

$params = array(
'grant_type' => 'refresh_token',
'refresh_token' => $refresh_token,
'client_id' => $this->config['clientId'],
'client_secret' => $this->config['clientSecret']
);

$data = "";
foreach ($params as $k => $v) {
$data .= "$k=" . rawurlencode($v) . "&";
}

$url = "https://$this->tokenUrl";

$request = new CurlRequest($this->config);
$request->setOption(CURLOPT_URL, $url);
$request->setOption(CURLOPT_HTTPHEADER, $headers);
$request->setOption(CURLOPT_USERAGENT, $this->userAgent);
$request->setOption(CURLOPT_POST, true);
$request->setOption(CURLOPT_POSTFIELDS, rtrim($data, "&"));

$response = $this->executeRequest($request);

$response_array = json_decode($response['response'], true);
if (is_array($response_array) && array_key_exists("access_token", $response_array)) {
$this->config['accessToken'] = $response_array['access_token'];
} else {
$this->logAndThrow("Unable to refresh token. 'access_token' not found in response. " . print_r($response,
true));
}
$this->config['accessToken'] = $refresh_token;

return $response;
}

/**
Expand Down

0 comments on commit 056ef4d

Please sign in to comment.