You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用华为Connect API获取上传URL时client token认证失败求助

华为Connect API获取上传URL时认证失败(错误码205524993)

我已在华为Connect门户创建API客户端(指定名称、项目字段填N/A、分配管理员角色),并成功获取API密钥。但调用API获取应用上传URL时,返回错误:

{"ret":{"code":205524993,"msg":"client token auth failed"}}

以下是我使用的PowerShell脚本:

#obtaining API key

$tokenHeader = @{
    "Content-Type"="application/json"
}

# Token request payload
$tokenRequest = @{
    grant_type    = "client_credentials"
    client_id     = $ClientId 
    client_secret = $ClientKey 
} | ConvertTo-Json

# Get Access Token
write-host "retrieving access token"
$accessTokenResponse = Invoke-WebRequest -Uri $authUrl -Method POST -Headers $tokenHeader -Body $tokenRequest

#obtaining Upload url 

$url = "https://connect-api.cloud.huawei.com/api/publish/v2/upload-url/appId=$appId&suffix=aab"
$headers = @{
    "client_id" = "$clientId"
    "Content-Type" = "application/json"
    "Authorization" = "Bearer $accessTokenResponse.content"
}

$response = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers

恳请协助排查认证失败原因。


问题排查与修复方案

  • 访问令牌解析错误:$accessTokenResponse.content返回的是完整JSON响应(包含access_token字段),直接拼接进Authorization头会导致令牌无效。需先解析JSON提取有效令牌:

    # 解析令牌响应,提取access_token
    $tokenResult = $accessTokenResponse.Content | ConvertFrom-Json
    $accessToken = $tokenResult.access_token
    
    # 构造正确的Authorization头
    "Authorization" = "Bearer $accessToken"
    
  • 变量名不一致:脚本中定义的上传URL变量是$url,但调用Invoke-RestMethod时用的是$uri,导致请求地址错误,间接引发认证校验失败。需统一变量名:

    $uri = "https://connect-api.cloud.huawei.com/api/publish/v2/upload-url/appId=$appId&suffix=aab"
    
  • 冗余请求头干扰:华为Connect的上传URL接口不需要在请求头中携带client_id和Content-Type(GET请求无请求体),多余字段可能干扰认证逻辑,建议移除这两个头字段。

内容的提问来源于stack exchange,提问作者Abul_Hassan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 10:44:51