Tokens for ExportTileCacheTask

3065
10
01-05-2016 01:31 PM
RobertJohnson5
New Contributor

I'm trying to create an app with offline capabilities, but I've run into an issue trying to set a basemap. Basically, I can't figure out how to pass a token into the ExportTileCacheTask to allow user to download a tpk from one of Esri's tiled map services for use when they're offline. Has anyone done this before?

0 Kudos
10 Replies
LucasDanzinger
Esri Frequent Contributor

Robert-

You can use UserCredentials for this. Set the username and password on the UserCredentials, and pass that into the credentials property (or setter if using C++) of the task. This should take care of acquiring the token based on your credentials and then making the required REST requests.

-Luke

0 Kudos
RobertJohnson5
New Contributor

Thanks for the quick response.  I should mention that we're trying to use the OAuth app login and would like to avoid hard coding any username or password information as that doesn't seem too secure. I haven't been able to find any sample code using OAuth that doesn't require a login prompt. Since this is going to be an app for the general public to use, that wouldn't really work either.

There's probably something simple that I'm missing, but I don't really know where to go from here.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

If you are using OAuth and you don't want to have your user sign in, it sounds like you will need to use app logins. This guide topic explains how you can do this, and how you can populate the UserCredentials object with the proper information so that it can then be passed into the task. Use OAuth 2.0 authentication—ArcGIS Runtime SDK for Qt | ArcGIS for Developers

0 Kudos
ShaneFeirer
New Contributor III

Is their a working example of using oauth app login that uses the clientid and clientsecret.  I have looked at the documentation that you referenced and it is not obvious how to implement this in qt.  I looked at the qt sample app and it does not have an example that uses the clientid and client secret workflow.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

We don't have a sample available. I guess I should've clarified before. Is your service hosted in AGOL/Portal or is it a regular ArcGIS Server service that you are connecting to?

0 Kudos
ShaneFeirer
New Contributor III

We are trying to create a tile package from the esri world imagery (for export) http://www.arcgis.com/home/item.html?id=226d23f076da478bba4589e7eae95952 for use when in offline mode of the app.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Hey Shane-

I put together a quick sample that should hopefully get you on the right track. Please see the readme for a few details.

RuntimeQtSamples/export_tiles_from_service at master · ldanzinger/RuntimeQtSamples · GitHub

Hopefully this helps.

-Luke

0 Kudos
ShaneFeirer
New Contributor III

Thank you for this sample.  That has helped a lot.  I noticed one issue with the following section:

  onMapServiceInfoStatusChanged: {
   if (mapServiceInfoStatus === Enums.MapServiceInfoStatusCompleted) {
   console.log("Service info received");
   taskParams.initialize(mapServiceInfo);
   console.log("Estimating size...");
   taskParams.minLevelOfDetail = minScaleTextBox.text;
   taskParams.maxLevelOfDetail = maxScaleTextBox.text;
   exportTask.estimateTileCacheSize(taskParams);
  } else if (mapServiceInfoStatus === Enums.MapServiceInfoStatusErrored){
   console.log("Error:", mapServiceInfoError.message);
  }
  }

Inorder to get it to download what was in the extent I added taskParams.extent = map.extent;,

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Thanks Shane, glad it helped. I updated the code to reflect your statement.

Have a nice weekend.

-Luke