Skip to content

Instantly share code, notes, and snippets.

@greenstork
Created August 9, 2013 17:51
Show Gist options
  • Save greenstork/6195609 to your computer and use it in GitHub Desktop.
Save greenstork/6195609 to your computer and use it in GitHub Desktop.
//constructor
public PubHomeController() {
pub = [SELECT id FROM Network WHERE Name LIKE '%Power of Us%'];
}
public class Topic {
public String createdDate { get; private set; }
public String id { get; private set; }
public String description { get; private set; }
public Integer talkingAbout { get; private set; }
public String name { get; private set; }
}
public class TopicResponse {
public list<Topic> topics;
}
public list<Topic> getTrendingTopics(){
try {
//we'll call the REST API here
http h = new http();
httprequest req = new httprequest();
req.setEndpoint(baseEndpoint + '/services/data/v28.0/connect/communities/' + pub.id + '/chatter/topics?pageSize=5');
req.setMethod('GET');
req.setHeader('Authorization', 'OAuth ' + session);
req.setTimeout(60000);
httpresponse res = h.send(req);
system.debug('TopicsResponseBody:' + res);
TopicResponse tr = (TopicResponse)JSON.deserialize(res.getBody(), TopicResponse.class);
return tr.topics;
} catch (Exception e) {
return null;
}
}
<h4>Popular Topics</h4>
<ul style="list-style-type: none;margin-left:0px;">
<apex:repeat value="{!TrendingTopics}" var="topic" >
<li><a href="/_ui/core/chatter/topics/TopicPage?id={!topic.id}" class="viewPopularTopic">#{!topic.name}</a></li>
</apex:repeat>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment