how to access content in a group through portal

782
6
Jump to solution
07-10-2017 01:53 PM
YifanLiu
New Contributor II

I need to access a secured feature layer that belongs to my group. I have implemented the OAuth login and am able to access my own content. However, I cannot seem to be able to find a way to reach into my groups content list. Anyone has any suggestions?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Regular Contributor

It is a two step process because for some reason when you query for the contents of a group you need the group id not the group name.

This will get you the PortalGroup object

private async Task<PortalGroup> GroupFromTitle(string groupTitle)
{
     PortalQueryParameters parameters = PortalQueryParameters.CreateForGroups("", groupTitle);

     PortalQueryResultSet<PortalGroup> groupResultSet = await _portal.FindGroupsAsync(parameters);
     PortalGroup offlineGroup = groupResultSet.Results.FirstOrDefault();
     return offlineGroup;
}

You can pass in the group from above and this will return the items in that group.

private async Task LoadItemsFromGroup(PortalGroup portalGroup, PortalItemType itemType)
{
     PortalQueryParameters groupParameters = PortalQueryParameters.CreateForItemsOfTypeInGroup(itemType, portalGroup.GroupId);

     PortalQueryResultSet<PortalItem> queryResultSet = await portalGroup.Portal.FindItemsAsync(groupParameters);

     foreach (var portalItem in queryResultSet.Results)
     {
          PortalItems.Add(new PortalListItem(portalItem));
     }
}

View solution in original post

6 Replies
NagmaYasmin
Occasional Contributor III

Hi Yifan,

Have you tried to use PortalItem.GetGroupsAsync() to get the list of the groups you have access. I think once you get the access of theat group, you may find the list of the available contents in that group.

PortalItem Methods --> "Gets the groups the item is a part of. Only shows the groups which the calling user can access."

Hope that helps.

Nagma

YifanLiu
New Contributor II

The PortalGroup class, which can be accessed through getGroupsAsync, does not provide a way to see the content in the group. But thanks still Nagma!

0 Kudos
JoeHershman
MVP Regular Contributor

Is the issue not knowing how to query a group or not seeing the group event though you are a member?  The former would be answered using the method described above, and there are various ways to query groups.  I have come across the latter issue which required a Portal reboot.  I don't understand why this is, just know it solved the problem.  I had groups that I was a member, I could log onto Portal through the browser and see the group and content, however, when I queried from Runtime the groups were not found.  After pulling out my hair for a few hours decided to reboot Portal and that fixed the issue. 

0 Kudos
YifanLiu
New Contributor II

Could you elaborate how to query group content? GetGroupsAsync does not seem to provide a way to query the content in a group.

0 Kudos
JoeHershman
MVP Regular Contributor

It is a two step process because for some reason when you query for the contents of a group you need the group id not the group name.

This will get you the PortalGroup object

private async Task<PortalGroup> GroupFromTitle(string groupTitle)
{
     PortalQueryParameters parameters = PortalQueryParameters.CreateForGroups("", groupTitle);

     PortalQueryResultSet<PortalGroup> groupResultSet = await _portal.FindGroupsAsync(parameters);
     PortalGroup offlineGroup = groupResultSet.Results.FirstOrDefault();
     return offlineGroup;
}

You can pass in the group from above and this will return the items in that group.

private async Task LoadItemsFromGroup(PortalGroup portalGroup, PortalItemType itemType)
{
     PortalQueryParameters groupParameters = PortalQueryParameters.CreateForItemsOfTypeInGroup(itemType, portalGroup.GroupId);

     PortalQueryResultSet<PortalItem> queryResultSet = await portalGroup.Portal.FindItemsAsync(groupParameters);

     foreach (var portalItem in queryResultSet.Results)
     {
          PortalItems.Add(new PortalListItem(portalItem));
     }
}
YifanLiu
New Contributor II

This is exactly what I need, thank you!

0 Kudos