PortalUser::addToFavorites is not working

3 weeks ago
New Contributor

What I done:
1. connected to the signal
connect(m_portal->portalUser(), &Esri::ArcGISRuntime::PortalUser::addToFavoritesCompleted, this, [](bool success)

2. called the method:

3. inside the connected lambda I always get false, and an item is not added to favorites.

And what I checked:
1. User is definitely logged in, because I can read favorites/groups/username etc

2. m_webmaps->at(itemId.toInt()) is the proper item, because I can call m_webmaps->at(itemId.toInt())->title() and compare it with the title of an item that I clicked on (they are the same items).

0 Kudos
3 Replies
New Contributor

Thanks for your answer, ABladon!

You are right, I got an error: "You do not have permissions to access this resource or perform this operation."
I logged in via m_portal->setCredential() and then m_portal->load(). Is it not enough to just set credentials?

0 Kudos
Esri Contributor

Hi LucDeBatselier.

Access to a resource is granted by the item provider. For example, an author on ArcGIS online can assign different sharing levels to an item, including:

  • Everyone (i.e. public).
  • People in an organization.
  • People in a user group.
  • The author of the item only (i.e. private).

See here for more information on sharing items.

To enable a user to add a PortalItem to a favourites list, the user must be granted access to the PortalItem by the item provider.

Hopefully reviewing the sharing levels of the PortalItem’s being accessed will help you resolve the issue.

0 Kudos
Esri Contributor

Thanks for getting in touch LucDeBatselier!

We have created a simple app to test the PortalUser::addToFavorites() method and to recreate your issue.

The addToFavorites() method appears to be working. However, we are able to recreate your issue if an error occurs while trying to add a PortalItem to a PortalUser’s favourites (e.g. a user not having the appropriate permissions).

To help identify whether an error could be causing your issue, we suggest creating a connection between the PortalUser::errorOccurred signal and a slot that prints out the error message(s). For example:

connect(m_portal->portalUser(), &PortalUser::errorOccurred, this, [](Error error){

    qDebug() << error.message() << error.additionalMessage();


Hopefully this helps! Let us know if the issue remains after checking for and resolving any errors.

0 Kudos