What I done:
1. connected to the signal
connect(m_portal->portalUser(), &Esri::ArcGISRuntime::PortalUser::addToFavoritesCompleted, this, [](bool success)
2. called the method:
m_portal->portalUser()->addToFavorites(m_webmaps->at(itemId.toInt()));
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).
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?
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:
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.
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.
Thanks for your answer, Andrew Bladon!
I subscribed to PortalUser::errorOccurred, and when I tried to add item to favorites I got an error message:
Error: "PortalItem must be loaded before adding item to favorites."
Additional error: ""
And then PortalUser::addToFavoritesCompleted returned false, what is logically.
So, the first problem is clear: not only portal, but also portal item must be loaded.
Then I loaded portal item:
m_webmaps->at(itemId.toInt())->load();
(where m_webmaps is QScopedPointer<Esri::ArcGISRuntime::PortalItemListModel>
and itemId is just number of the item in list.)
Then I checked if portal item is loaded:
m_webmaps->at(itemId.toInt())->loadStatus() == Esri::ArcGISRuntime::LoadStatus::Loaded
and tried to add item to favorites again:
m_portal->portalUser()->addToFavorites(m_webmaps->at(itemId.toInt()));
, but now neither PortalUser::addToFavoritesCompleted nor PortalUser::errorOccurred are triggered...
I got only message Licensed for Developer Use Only in the console.
May be you have any ideas and solutions for it?
m_webmaps->at(itemId.toInt())->load();
if (m_webmaps->at(itemId.toInt())->loadStatus() == LoadStatus::Loaded)
m_portal->portalUser()->addToFavorites(m_webmaps->at(itemId.toInt()));
// Define connection.
connect(m_webmaps->at(itemId.toInt()), &PortalItem::doneLoading, this, [](Error error){
if (!error.isEmpty())
qDebug() << error.message() << error.additionalMessage();
else if (m_webmaps->at(itemId.toInt())->loadStatus() == Esri::ArcGISRuntime::LoadStatus::Loaded)
m_portal->portalUser()->addToFavorites(m_webmaps->at(itemId.toInt()));
});
// Load PortalItem.
m_webmaps->at(itemId.toInt())->load();