Getting a List of Topics

Getting a list of application-scope topics

You can get a list of all application scope topic. If there are more than 50 topics, you need to get the topic list in multiple pages with the pagination.

The following is the sample code for getting a list of all application scope topics.

  • try {
      // Get the first page of the topic list.
      KiiListResult<KiiTopic> result = Kii.listTopics();
      for (KiiTopic topic : result.getResult()) {
        // Do something.
      }
    
      if (result.hasNext()) {
        // Get the next page of the topic list.
        result = Kii.listTopics(result.getPaginationKey());
        for (KiiTopic topic : result.getResult()) {
          // Do something.
        }
      }
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • // Get the first page of the topic list.
    Kii.listTopics(new KiiCallback<KiiListResult<KiiTopic>>() {
      @Override
      public void onComplete(KiiListResult<KiiTopic> result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
        for (KiiTopic topic : result.getResult()) {
          // Do something.
        }
    
        if (result.hasNext()) {
          // Get the next page of the topic list.
          Kii.listTopics(result.getPaginationKey(), new KiiCallback<KiiListResult<KiiTopic>>() {
            @Override
            public void onComplete(KiiListResult<KiiTopic> result, Exception e) {
              // Do something.
            }
          });
        }
      }
    });

This is the brief explanation of the sample code:

  • Execute the listTopics method to get a list of topics.
  • Execute the getResult method to get the topic list as a List.
  • Execute the hasNext method to check if there exist more topics to get. If there are ones, execute the getPaginationKey to get a key and execute the listTopics again with this key.

Getting a list of group-scope topics

You can get a list of all topics in the specified group scope. If there are more than 50 topics, you need to get the topic list in multiple pages with the pagination.

The following is the sample code for getting a list of all topics in a group scope.

  • try {
      // Instantiate an existing group.
      KiiGroup group = KiiGroup.createByUri(groupUri);
    
      // Get the first page of the topic list.
      KiiListResult<KiiTopic> result = group.listTopics();
      for (KiiTopic topic : result.getResult()) {
        // Do something.
      }
    
      if (result.hasNext()) {
        // Get the next page of the topic list.
        result = group.listTopics(result.getPaginationKey());
        for (KiiTopic topic : result.getResult()) {
          // Do something.
        }
      }
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • // Instantiate an existing group.
    final KiiGroup group = KiiGroup.createByUri(groupUri);
    
    // Get the first page of the topic list.
    group.listTopics(new KiiCallback<KiiListResult<KiiTopic>>() {
      @Override
      public void onComplete(KiiListResult<KiiTopic> result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
        for (KiiTopic topic : result.getResult()) {
          // Do something.
        }
    
        if (result.hasNext()) {
          // Get the next page of the topic list.
          group.listTopics(result.getPaginationKey(), new KiiCallback<KiiListResult<KiiTopic>>() {
            @Override
            public void onComplete(KiiListResult<KiiTopic> result, Exception e) {
              // Do something.
            }
          });
        }
      }
    });

This is the brief explanation of the sample code:

  • Execute the listTopics method to get a list of topics.
  • Execute the getResult method to get the topic list as a List.
  • Execute the hasNext method to check if there exist more topics to get. If there are ones, execute the getPaginationKey to get a key and execute the listTopics again with this key.

Getting a list of user-scope topics

You can get a list of all topics in the specified user scope. If there are more than 50 topics, you need to get the topic list in multiple pages with the pagination.

The following is the sample code for getting a list of all topics in a user scope.

  • try {
      // Get the currently logged-in user.
      KiiUser user = KiiUser.getCurrentUser();
    
      // Get the first page of the topic list.
      KiiListResult<KiiTopic> result = user.listTopics();
      for (KiiTopic topic : result.getResult()) {
        // Do something.
      }
    
      if (result.hasNext()) {
        // Get the next page of the topic list.
        result = user.listTopics(result.getPaginationKey());
        for (KiiTopic topic : result.getResult()) {
          // Do something.
        }
      }
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • // Get the currently logged-in user.
    final KiiUser user = KiiUser.getCurrentUser();
    
    // Get the first page of the topic list.
    user.listTopics(new KiiCallback<KiiListResult<KiiTopic>>() {
      @Override
      public void onComplete(KiiListResult<KiiTopic> result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
        for (KiiTopic topic : result.getResult()) {
          // Do something.
        }
    
        if (result.hasNext()) {
          // Get the next page of the topic list.
          user.listTopics(result.getPaginationKey(), new KiiCallback<KiiListResult<KiiTopic>>() {
            @Override
            public void onComplete(KiiListResult<KiiTopic> result, Exception e) {
              // Do something.
            }
          });
        }
      }
    });

This is the brief explanation of the sample code:

  • Execute the listTopics method to get a list of topics.
  • Execute the getResult method to get the topic list as a List.
  • Execute the hasNext method to check if there exist more topics to get. If there are ones, execute the getPaginationKey to get a key and execute the listTopics again with this key.