Marvel API 返回无效凭证

问题描述 投票:0回答:2

我正在使用 Marvel API。

我设置了时间戳、apikey 和 hash(ts+privateKey+apiKey).md5

// ts
let ts = String(Date().timeIntervalSince1970)

// apiKey
"cfd8392fa89be1a574b402a9c54f9c52"

// privateKey
"d3ea745cf73f7a7278e1368ffe3b50f4bdb2746"

我使用 Postman 进行了测试。但是响应始终是 401 无效凭据。

/// URL
https://gateway.marvel.com:443/v1/public/characters?ts=1649942740.2140222&apikey=cfd8392fa89be1a574b402a9c54f9c52&hash=d9a73e6105271137942b5ea743ae2ad2
{
    "code": "InvalidCredentials",
    "message": "That hash, timestamp and key combination is invalid."
}

我已经在我的开发者帐户 - Marvel

设置了带 *(星号)的授权裁判

请帮助我。我不知道我错过了什么。

swift api
2个回答
0
投票

将时间戳、私钥和公钥转换为

md5
哈希值。然后将其用作查询字符串。

import CryptoKit


let ts = String(Date().timeIntervalSince1970)
let hash = MD5(string:"\(ts)\("PRIVATE_KEY")\("PUBLIC_KEY")")


func MD5(string: String) -> String {
    let digest = Insecure.MD5.hash(data: string.data(using: .utf8) ?? Data())
    return digest.map {
        String(format: "%02hhx", $0)
    }.joined()
}

0
投票

您已使用

\ts\privatekey\publickey
而不是
tsprivatekeypublickey

创建了 md5 哈希值

输入应该是

let hash = MD5(string:"ts+PRIVATE_KEY+PUBLIC_KEY")

© www.soinside.com 2019 - 2023. All rights reserved.