【问题标题】:Zoho crm :STUCK on Step 3: Generate Access Token and Refresh TokenZoho crm:第 3 步:生成访问令牌和刷新令牌
【发布时间】:2018-12-10 14:04:38
【问题描述】:

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

【问题讨论】:

  • 您好,您解决了这个问题吗?我遇到了同样的错误

标签: php curl zoho


【解决方案1】:

//记得根据您的 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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 尝试刷新令牌时代码不起作用总是出错:invalid_code
    猜你喜欢
    • 2020-08-11
    • 2020-04-14
    • 2019-05-31
    • 1970-01-01
    • 2023-04-04
    • 2020-01-09
    • 2021-08-23
    • 2015-04-01
    • 2019-03-08
    相关资源
    最近更新 更多