• 13

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I'm trying to run a call to Marvel Api however the return I'm having is code = 401 Unauthorized, this is due to not being able to send the timeStamp and hash parameters correctly.

the url base is http://gateway.marvel.com/v1/public/ -> my url is being: = http: //gateway.marvel.com/ v1 / public / characters? name = wolverine & apikey = XXX & ts = 2019-04-06% 2013: 09: 10.272 & hash = [B @ afad7ce8] In the documentation it is described that I need to send these parameters: Params: {    "apikey": "your api key",    "ts": "a timestamp",    "hash": "your hash" } I need help to generate the ts and hash correctly. Note: hash = ts + apiKey + publicKey

var ts = Timestamp(System.currentTimeMillis())
var hash = getHash(ts.toString())

fun getHash(ts: String): ByteArray? {
        val byte = ts.toByteArray() + API_KEY.toByteArray() + PUBLIC_KEY.toByteArray()
        val md = MessageDigest.getInstance("MD5")

        return md.digest(byte)

You should not put your private key in code (it's bad practice and usually with this key you can do CRUD operations with API and even drop some parts of database).

Get your Marvel public key (for example 1234), your private key(for example abcd) and choose timestamp (for example 1564731162583).

Go to website https://passwordsgenerator.net/md5-hash-generator/ put your strings like 1564731162583abcd1234 (timestamp + private key + api key without spaces). You will get (with parameters from example) hash: B5936DEBCC1A252C679D2D3E5361B6C0

One more important thing: when you add this hash in your api call, timestamp have to be the same as in hash (previously chosen example 1564731162583) and also MD5 hash have to be in lowercase. This is important.

Hope it will help :)

  • 1
Reply Report