qtqmlhere-apihere-maps-restqtlocation

Qt Qml Map with HERE plugin how to correctly authenticate using here.token


I'm struggling to authenticate in HERE plugin. I'm using windows 10 with Qt 5.9.1 Mingw 32bit and my app is almost all written in c++. The only part Where I use QML is about the map. I want to use the HERE plugin, but I am a newbie with QtLocation and plugins, and I really can't understand what I need to do to authenticate in HERE. I tried to follow the guide on the HERE site but I really can't understand.

I know from qt that the code I must use to athenticate on HERE is the following:

Plugin {
    name: "here"
    PluginParameter { name: "here.app_id"; value: "myapp" }
    PluginParameter { name: "here.token"; value: "abcdefg12345" }
}

So I need here.app_id and here.token.

I created an account on the HERE site and I created a project using REST. So now I have my APP ID parameter but I really don't understand how to get the TOKEN value to put in the second line. First of all for my specific case I need to create an api key or an OAuth 2.0?

I tried to follow what is written in this link using Postman and at the end I got a really long tokoen that I copied and put in the "here.token" parameter but when I run the application it gives me Invalid here.token and it does not display the map.

Can somebody give me any hint on how to correctly get the token value? Or can somebody point me to some links? Is there a different way to login using an api key for example instead of the token?

---------------- UPDATE ---------------------------------------

After some time I had to return on this problem that I never solved: the situation right now is that I manage to get the token through postman but it's always invalid. Right now I'm using Qt 5.15.2 and MinGw 64 bit.

I'm using the minimal_map example modified to add the here.app_id and here.token parameter.

main.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtLocation 5.6
import QtPositioning 5.6

Window {
    width: Qt.platform.os == "android" ? Screen.width : 512
    height: Qt.platform.os == "android" ? Screen.height : 512
    visible: true

    Plugin {
        id: mapPlugin
        name: "here" // "mapboxgl", "esri", ...
        // specify plugin parameters if necessary
        parameters: [
         PluginParameter {
             name: "here.app_id"
             value: "xxxxx"
         },
         PluginParameter {
             name: "here.token"
             value: "yyyyyy"
         }]
    }

    Map {
        anchors.fill: parent
        plugin: mapPlugin
        center: QtPositioning.coordinate(59.91, 10.75) // Oslo
        zoomLevel: 14
    }
}

the problem is that when I run the app the output is the following:

Invalid here.token
3 ,  "Qt Location requires app_id and token parameters.\nPlease register at https://developer.here.com/ to get your personal application credentials."

To get the token I've done the following:

  1. I registered myself at developer.here site with a Freemium plan and I created a project.
  2. I created a REST API and an OAuth 2.0 (JSON Web Tokens) as follows (I saved the credentials.properties files that I used in the 3. step): 1.PNG
  3. I download Postman, I created an account and I followed the instruction from the answer to this question. I received response in a json format like this: 3.png a
  4. I went in my minimal_map example and I set as app_id (instead of "xxxxx") the APP ID value displayed inside the first image I posted and as here.token (instead of the "yyyyyy") the acces_token received in the JSON response from POSTMAN.
  5. I tried to clean the project, delete the build folder but nothing changed, the answer is always:
Invalid here.token
3 ,  "Qt Location requires app_id and token parameters.\nPlease register at https://developer.here.com/ to get your personal application credentials."

What am I missing to get a token to display the here plugin in Qt?


Solution

  • The HERE service has been updated but Qt has not updated its plugin.

    The main changes are:

    That is, you have to change the request from:

    http://X.api.here.com/?app_code={here.app_code}&app_id={here.app_id}&{other_parameters}
    

    to

    https://X.ls.here.com/?apiKey={here.apiKey}&{other_parameters}
    

    Qt 5.14:

    Considering the above I have created a patch that implements the above, so to use it you must follow the following procedure:

    git clone https://code.qt.io/qt/qtlocation.git
    cd qtlocation
    git checkout 5.14
    wget https://raw.githubusercontent.com/eyllanesc/stackoverflow/master/questions/60544057/Qt5.14/update-HERE-Qt5.14.patch
    git config --global user.email "you@example.com"
    git am < update-HERE-Qt5.14.patch
    qmake .
    make
    make install
    

    Qt 5.9:

    Considering the above I have created a patch that implements the above, so to use it you must follow the following procedure:

    git clone https://code.qt.io/qt/qtlocation.git
    cd qtlocation
    git checkout 5.9
    wget https://raw.githubusercontent.com/eyllanesc/stackoverflow/master/questions/60544057/Qt5.9/update-HERE-Qt5.9.patch
    git config --global user.email "you@example.com"
    git am < update-HERE-Qt5.9.patch
    qmake .
    make
    make install
    

    Window {
        visible: true
        width: 640
        height: 480
        Plugin {
            id: mapPlugin
            name: "here"
            PluginParameter { name: "here.apiKey"; value: "{YOUR_API_KEY}" }
        }
        Map {
            anchors.fill: parent
            plugin: mapPlugin
            center: QtPositioning.coordinate(59.91, 10.75) // Oslo
            zoomLevel: 14
        }
    }
    

    enter image description here


    UPDATE

    Here service provides various authentication systems with different access urls. So considering the above I have tried each of those cases and I have found that Qt uses HERE SDK FOR IO or HERE SDK FOR ANDROID (in my part before my answer it is used for authentication type REST).

    So in this case you must activate one of those types of authentications:

    enter image description here

    enter image description here

    In the case of the HERE SDK FOR IOS or HERE SDK FOR ANDROID you must set any value for the bundle or package name, respectively.

    So you must use APP ID for here.app_id and APP CODE for here.token:

    Plugin {
        id: mapPlugin
    
        name: "here"
        parameters: [
            PluginParameter {
                name: "here.app_id"
                value: "APP_ID"
            },
            PluginParameter {
                name: "here.token"
                value: "APP_CODE"
            }
        ]
    }