PHP SDK: generateAccessTokenFromRefreshToken returning NULL
Hello all,
I'm having problems generating the access token from refresh token when using the generateAccessTokenFromRefreshToken function.
Firstly, I'm using CURL to receive both the access_token and refresh_tokens. Maybe this is where I am going wrong, as the access token is already successfully created?
If anyone could help, that would be great. Please see code below:
- $curl = curl_init();
- curl_setopt_array($curl, array(
- CURLOPT_URL => "https://accounts.zoho.eu/oauth/v2/token?client_id=" . $clientId . "&client_secret=" . $clientSecret . "&redirect_uri=" . $redirectUri . "&code=" . $grantToken . "&grant_type=authorization_code",
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => "",
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_TIMEOUT => 30,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_CUSTOMREQUEST => "POST",
- CURLOPT_HTTPHEADER => array(
- "Accept: */*",
- "Accept-Encoding: gzip, deflate",
- "Cache-Control: no-cache",
- "Connection: keep-alive",
- "Content-Length: ",
- "Cookie: a5581ceb1f=0f0996ff9f95d2f31a5b3a5b981d1903; iamcsr=046c84ea-a41e-4a60-9542-701f04a748ce",
- "Host: accounts.zoho.eu",
- "Postman-Token: 5a8433a2-851d-429a-9fe5-cac34d916478,55819d99-d09c-47d3-a137-ad5439e0f7b3",
- "User-Agent: PostmanRuntime/7.15.2",
- "cache-control: no-cache"
- ),
- ));
- $response = curl_exec($curl);
- $err = curl_error($curl);
- curl_close($curl);
- if ($err) {
- echo $error;
- return;
- }
- $decodedResponse = json_decode($response, true);
- if (array_key_exists("error", $decodedResponse)) {
- echo $decodedResponse["error"];
- return;
- }
- if (!array_key_exists("access_token", $decodedResponse) ||
- !array_key_exists("refresh_token", $decodedResponse)) {
- echo "No access_token or refresh_token";
- return;
- }
- $accessToken = $decodedResponse["access_token"];
- $refreshToken = $decodedResponse["refresh_token"];
- echo $accessToken;
- echo "<br>";
- echo $refreshToken;
- $configuration = array(
- "client_id"=> $clientId,
- "client_secret"=> $clientSecret,
- "redirect_uri" => $redirectUri,
- "currentUserEmail"=> "zoho.developer1@infarm.com",
- "accounts_url" => "https://accounts.zoho.eu"
- );
- ZCRMRestClient::initialize($configuration);
- $oAuthClient = ZohoOAuth::getClientInstance();
- $userIdentifier = "zoho.developer1@infarm.com";
- $oAuthTokens = $oAuthClient->generateAccessTokenFromRefreshToken($refreshToken, $userIdentifier);
- var_dump($oAuthTokens);
- $rest = ZCRMRestClient::getInstance();
- $orgIns = $rest->getOrganizationDetails()->getData();