1

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?

Salvo
  • 286
  • 2
  • 20
  • See https://developer.here.com/projects – eyllanesc Mar 05 '20 at 23:11
  • @eyllanesc ad I said in the post I already created a project and I got in the REST section my APP_ID and API KEY. But I'm struggling getting the here.token necessary to authenticate in to use the plugin in a qml map. – Salvo Mar 06 '20 at 09:14
  • 1
    Okay, I have analyzed the Qt HERE plugin and it seems that it is outdated, I am updating it to comply with the rules of the new HERE API (I could already show the map but I am still working on the geocode, reverse-geocode, etc) When I finish it I will publish the solution – eyllanesc Mar 06 '20 at 22:03
  • Qt map examples seem to work alright with HERE maps. Possibly only a temporary outage? I don't think they can axe legacy endpoints easily. There are devices out there still using them who have a contract. For example, Sailfish OS devices that are stuck on Qt 5.6. – Pa_ Mar 17 '20 at 13:50
  • @Pa_ Maybe is working right because you managed to get the correct here.token. I got my app_id from the here site, but even if I run an example (the minimal_map example on qt) it needs also the here.token, and the question was how to get the here.token since I tried everything without success. I'm doing something wrong but I don't know what. Can you help me on this? – Salvo Mar 18 '20 at 08:08
  • As far as i know the only way to get tokens is by registering at developer.here.com. If you are a commercial customer, i'm sure there should be no problem to provide you with one such pair of "legacy" tokens. – Pa_ Mar 21 '20 at 14:41
  • @Pa_ as I already said in my post, I already have an account at developer.here.com. Since I'm having problems getting the token (I followed the procedure on their site that uses Postman,, I left the link in my post) the answer is what actually is the right procedure to get the here token. I'm missing something so if somebody can help me with a step by step guide on how he/she managed to get a token I would really appreciate it. – Salvo Mar 24 '20 at 07:56
  • @Salvo Are you still using the code that Qt provides by default and you don't use the patch I have provided? – eyllanesc Apr 02 '21 at 16:11
  • @eyllanesc currently I've started a new project with Qt 5.15.2 and was asking if something has changed so that I don't have to build libraries myself. I've seen some people asking questions on Qt forum that apparently uses app_id and token without any problem. Moreover I was able to get the here.token using the method I posted above, so I would like to use the official libraries. If there is still a problem because HERE plugin in Qt must accept api key and not the token, it's better to reach Qt developers to officialy update the lib. But in this case this should be a big prob, am I wrong? – Salvo Apr 02 '21 at 16:56
  • @Salvo see my update – eyllanesc Apr 02 '21 at 18:15

1 Answers1

8

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

The main changes are:

  • The app_id and token is only necessary when using the HERE SDK, in the case of Qt the apiKey must be used.

  • The HERE services url has had the following changes:

  • Use https (it was previously accessible through http but not now).

  • The previous host had the format X.api.here.com but now it is X.ls.hereapi.com.

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"
        }
    ]
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thanks for yout answer! I'm just trying to do what you said but when running the **qmake . ** steps it gives me the following error: `C:\Qt\5.9.1\mingw53_32\qtlocation\src\plugins\geoservices\nokia>qmake . Info: creating stash file C:\Qt\5.9.1\mingw53_32\qtlocation\.qmake.stash Project ERROR: Could not find feature location-labs-plugin.` Am I missing something? – Salvo Mar 10 '20 at 08:57
  • 1
    @Salvo mmm, I had tested my code with Qt 5.14.1 and I just noticed that you use a very old version so it is expected to have incompatibilities so I will have to modify it for your version of Qt (you will have to wait for me), if you want see the changes I made you can check the patch: https://github.com/eyllanesc/stackoverflow/blob/master/questions/60544057/update-API-Qt5.14.1.patch – eyllanesc Mar 10 '20 at 11:45
  • @Salvo How do you install Qt? – eyllanesc Mar 10 '20 at 16:10
  • What do you mean? I've downloaded it from the site of Qt and launched the installer. Do you think I need to reinstall it? If you are asking why I'm still using the 5.9.1 MinGw 32bit version that's because I'm working on a project started 3 years ago and I never (maybe doing wrong) done a porting of the project to the newer version. – Salvo Mar 11 '20 at 08:09
  • @Salvo I asked him why it is sometimes necessary to install some extra packages. Try the solution for Qt 5.9 and tell me if you have problems – eyllanesc Mar 11 '20 at 13:37
  • I'm sorry for troubling you again, everything works until the **make** command that is not found. Also the **sudo make install** is not found... What should I do? sorry for such a stupid question. I've searched on the net but there is a lot of confusion. I tried using mingw32-make but it gives me the following at the end of the process: **mingw32-make: *** [sub-src-make_first] Error 2**. Anyway after that the **sudo** command is not found so I'm stuck on this... – Salvo Mar 12 '20 at 09:14
  • @Salvo mmm, my example is generic since each OS has its own "make". To make it simple after the "git am ..." step, open with Qt Creator the .pro that is in the qtlocation folder and press the build button. The sudo command thing is unnecessary and I forgot to delete it. – eyllanesc Mar 12 '20 at 09:21
  • I've cdone the build on Qt Creator as you said, but it give me this error while building: **:-1: error: [sub-positioning-qmake_all] Error 3** – Salvo Mar 12 '20 at 11:14
  • @Salvo In Qt Creator there are several tabs at the bottom, tell me what message is in the "Compile Output" tab – eyllanesc Mar 12 '20 at 16:31
  • "perl" non Š riconosciuto come comando interno o esterno, un programma eseguibile o un file batch. Project MESSAGE: perl -w C:\Qt\5.9.1\mingw53_32\bin\syncqt.pl -module QtPositioning -version 5.9.9 -outdir C:/Qt/5.9.1/mingw53_32/qtlocation C:/Qt/5.9.1/mingw53_32/qtlocation Project ERROR: Failed to run: perl -w C:\Qt\5.9.1\mingw53_32\bin\syncqt.pl -module QtPositioning -version 5.9.9 -outdir C:/Qt/5.9.1/mingw53_32/qtlocation C:/Qt/5.9.1/mingw53_32/qtlocation Makefile:122: recipe for target 'sub-positioning-make_first' failed – Salvo Mar 13 '20 at 08:00
  • mingw32-make[1]: Leaving directory 'C:/Qt/5.9.1/mingw53_32/qtlocation/src' mingw32-make[1]: *** [sub-positioning-make_first] Error 3 Makefile:42: recipe for target 'sub-src-make_first' failed mingw32-make: *** [sub-src-make_first] Error 2 08:56:31: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2. Error while building/deploying project qtlocation (kit: Desktop Qt 5.9.1 MinGW 32bit2) When executing step "Make" – Salvo Mar 13 '20 at 08:01
  • @Salvo It seems that you need to install "perl", download it and try again. On the other hand, if some parts of the error message are in your native language then you should translate it into English to make it easy to read. – eyllanesc Mar 13 '20 at 08:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/209556/discussion-between-salvo-and-eyllanesc). – Salvo Mar 13 '20 at 08:29
  • @eyllanesc perhaps it would be a good idea to file a bug report to the Qt project, and possibly also send the patch through their public codereview? Finally, just an idea, perhaps it might be preferable to recycle the "here.token" parameter, and simply mark the "app_id" as obsolete, or remove it altogether. This would retain a greater source compatibility in apps, by simply updating the token, often sourced via env vars. – Pa_ Mar 15 '20 at 12:13
  • @eyllanesc with the HERE SDK for Android it works. I lost days behind this problem and I just needed to use a different method. Thank you a lot. But I have some question about this. 1- why it is not documented? I mean, I never thought I would need to use the HERE SDK For ANDROID. This should be well documented by Qt 2) On Windows? I used the same method and everything works but well I'm explicitly using something for Android.. it should not work, am I wrong? The missing documentation is a big problem. Thanks again for your help. I'm really curious about the second question tho – Salvo Apr 02 '21 at 19:31
  • 1
    @Salvo Those questions you should ask the Qt developers (report it as a documentation bug). My speculation is that when that Qt plugin was developed then there was only one way to use the service. If you are using it on an android device then don't forget the INTERNET permissions (or similar). – eyllanesc Apr 02 '21 at 19:35
  • For those on this thread, I found a comment from Volker Hilsheimer on this abandoned effort to fix the plugin (https://codereview.qt-project.org/c/qt/qtlocation/+/302357) that old credentials should still work with the HERE plugin without these patches? Can anybody confirm that and do they have any information about how to acquire an "old credential"? – David K. Hess Apr 10 '21 at 13:37
  • @DavidK.Hess Just my updated answer indicates that, the problem is that HERE currently there are several authentication methods and Qt does not indicate which of them should be used. – eyllanesc Apr 10 '21 at 17:03
  • @eyllanesc If you read his note, he seems to be saying that the method for authentication that the plugin is coded for *before* the current authentication methods still works *if* you can get an "old credential" for that previous method. I'm trying to figure out if it is possible to request an old credential for this previous method and how to do so. More info here: https://bugreports.qt.io/browse/QTBUG-84563 – David K. Hess Apr 10 '21 at 18:25
  • @DavidK.Hess If you manage to figure it out, can you reply to this comment? I'm just curious, actually the solution posted by eyllanesc works very well. – Salvo Jun 11 '21 at 08:34
  • @Salvo, I gave up on getting the plugin to work for geocoding and just used XMLHttpRequest instead of the plugin to talk to the HERE API directly. It's a pretty simple API to work with. – David K. Hess Jun 11 '21 at 12:46