1

I'm looking for a way to get all the sites I'm following by using JavaScript. What's the best way to do this?

3

You can use REST API to get the followed sites.

Below is the REST endpoint

GET http://<siteCollection>/<site>/_api/social.following/my/followedsitesuri

you can get more details on below MSDN link https://msdn.microsoft.com/en-us/library/dn194080.aspx

4
  • I also found below codeplex solution for this: iamfollowing.codeplex.com
    – Amit
    Jan 30 '15 at 12:18
  • Thanks, but I found this one is a better URL http://<siteCollection>/<site>_api/social.following/my/followed(types=4)
    – jlai
    Feb 2 '15 at 8:23
  • @jlai79 how is that endpoint better? I can understand by reading Amit's answer what the endpoint should return...
    – John-M
    Feb 3 '15 at 2:23
  • 2
    @John-M Amit's MSDN link gives the answer: My/FollowedSitesUri Gets the URI to the Sites I'm following page for the current user, My/Followed Gets ... sites ... that the current user is following.
    – jlai
    Feb 3 '15 at 8:30
0

This can be achieved using JSOM as well.

function getAllFavorites() {
        var clientContext = SP.ClientContext.get_current();
        var followingManager = new 
              SP.Social.SocialFollowingManager(clientContext);
        var documents = new SP.Social.SocialActorInfo();
        documents = followingManager.getFollowed(15);

       /*15 is to get users, documents, sites and tags that the logged
        in user is following. For more details
        https://msdn.microsoft.com/en-us/library/office/jj667835.aspx */

        var actorTypes = ['User', 'Document', 'Site', 'Tag'];

        clientContext.executeQueryAsync(function() {
           documents.forEach(function (doc, i) {
                    var item = {};
                    item.Name = doc.get_name();
                    item.actorType = actorTypes[doc.get_actorType()];
                    item.url = doc.get_uri();
                    $scope.favorites.push(item);
                });                               
        }, function(sender, args) {
            alert("Error: " + args.get_message());
        });
    }

SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function () {
            SP.SOD.executeFunc('userprofile', 
'SP.Social.SocialFollowingManager', function () {
   getAllFavorites();

/*This is to make sure the methods SP.ClientContext and 
SP.Social.SocialFollowingManager are loaded for the method
to work */

});
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.