Zoho crm:第3步上的STUCK:生成访问令牌和刷新令牌

时间:2018-12-10 14:04:39

标签: php curl zoho

我有$ 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 :(得分:0)

基于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);

答案 1 :(得分:0)

// 记住要根据您的zoho帐户更改值/网址。

要获取客户端ID和机密ID:https://accounts.zoho.com/developerconsole

一旦有了client-id,我们将使用它来生成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