Zoho crm: STUCK на шаге 3: создание токена доступа и обновления токена - PullRequest
0 голосов
/ 10 декабря 2018

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

enter image description here

$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);

Ответы [ 2 ]

0 голосов
/ 17 июня 2019

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

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

Как только у нас будет идентификатор клиента, мы будем использовать его для генерации oauth_token (access_token).

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

file_1 (zohoauth.php)

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

file_2 (testaccesstoken.php)

https://drive.google.com/file/d/1fBxBbt7IKI7vwgx6inaDnjtylSlSe4ye/view?usp=sharing
0 голосов
/ 10 декабря 2018

На основе 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);
...