Zoho crm: ЗАСТРЕЛ на шаге 3: сгенерируйте токен доступа и обновите токен

У меня есть $code и другие значения переменных, но я получаю сообщение об ошибке "Произошла ошибка сервера. Похоже, вы ввели неверный адрес или URL-адрес, по которому вы щелкнули, недействителен".

введите здесь описание изображения

$adminUrl='https://accounts.zoho.com/oauth/v2/token';


$data = array("code" => $code,
"redirect_uri" => $redirect_url, 
"client_id"=>$client_id, 
"client_secret" =>$client_secret, 
"grant_type"=> "authorization_code",
"scope" => "ZohoCRM.modules.ALL");

$data_string = json_encode($data,JSON_UNESCAPED_SLASHES);

$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)

);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $adminUrl);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);

$token = curl_exec($ch);

person Rishabh Kushwaha    schedule 10.12.2018    source источник
comment
Привет, ты решил эту проблему. Я получаю ту же ошибку   -  person Pritika    schedule 17.06.2019


Ответы (2)


//Не забудьте изменить значения/URL-адреса в соответствии с вашей учетной записью zoho.

Чтобы получить идентификатор клиента и секретный идентификатор: https://accounts.zoho.com/developerconsole

Получив client-id, мы будем использовать его для генерации oauth_token (access_token).

Вам понадобятся 2 файла, указанных ниже, чтобы получить oath_token (также называемый access_token).

файл_1 ( zohoauth.php )

https://drive.google.com/file/d/1yOfPBllcL3KEKIm_ooDxLJzc8a4NCDIu/view?usp=sharing

файл_2 ( testaccesstoken.php )

https://drive.google.com/file/d/1fBxBbt7IKI7vwgx6inaDnjtylSlSe4ye/view?usp=sharing
person Rishabh Kushwaha    schedule 17.06.2019

На основе API https://www.zoho.com/mail/help/api/using-oauth-2.html

Сгенерировать токен

GET oauth/v2/auth 
Host:: https://accounts.zoho.com

Query String:

https://accounts.zoho.com/oauth/v2/auth
?response_type=code 
&client_id=1000.R2*************************5EN
&scope=VirtualOffice.folders.READ
&redirect_uri=https://zylkerapps.com/oauth2callback
&state=-54****************5

Пример кода

$redirectTo = 'https://accounts.zoho.com/oauth/v2/auth' . '?' . http_build_query(
    [
     'client_id'     => $client_id,
     'redirect_uri'  => $redirect_url,
     'scope'         => 'ZohoCRM.modules.ALL',
     'response_type' => 'code',
    ]);
header('Location: ' . $redirectTo);
exit;

Обновить токен

POST https://accounts.zoho.com/oauth/v2/token

HOST:: https://accounts.zoho.com

Query String:

?refresh_token=1000.4069dacb56****************************************bcf902062390367
&grant_type=refresh_token
&client_id=1000.R2Z0W*********************Q5EN
&client_secret=39c**********************************921b
&redirect_uri=https://zylkerapps.com/oauth2callback
&scope=VirtualOffice.folders.UPDATE

Пример кода

$params = [
    'refresh_token' => $refresh_token,
    'grant_type'    => 'refresh_token',
    'client_id'     => $client_id,
    'client_secret' => $client_secret,
    'redirect_uri'  => $redirect_url,
    'scope'         => 'ZohoCRM.modules.ALL'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.zoho.com/oauth/v2/token');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close ($ch);
person Clément Baconnier    schedule 10.12.2018
comment
код не работает при попытке обновить токен, всегда возникает ошибка: invalid_code - person Navin Bhudiya; 21.12.2019