2

i have below code to fetch the followed sites of my online and its working fine ..but when i am trying to retrieve the office365 group sites... this code doesn't return me those sites..

Any suggestions to retrieve the team sites followed by me under office 365 group.

any help will be appreciated ..

below is my code `CCPortal.Home.FavoriteSites = (function () { 'use strict';

      var results, iLimit = 0;;
    function InitFavoriteSites() {
        $('#pnlFavoriteSites').text("Favorite Sites");
        SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function () {                               
            ExecuteOrDelayUntilScriptLoaded(getFavoriteSites, "sp.userprofiles.js");                                 
        });
    }      

    function getFavoriteSites() {

        var favArr , siteJson,follow, allSitesJson = [], FavoriteStar;
        var clientContext = SP.ClientContext.get_current();
        var followingManager = new  SP.Social.SocialFollowingManager(clientContext);
        var documents = new SP.Social.SocialActorInfo();
        documents = followingManager.getFollowed(4);  
        clientContext.executeQueryAsync(function () {

            documents.forEach(function (doc, i)
            {
                var item = {};
                item.Name = doc.get_name();                    
                item.url = doc.get_uri();
                follow = 'CumminsIconFav Star';                    
                siteJson = ({ Title: doc.get_name(), URL: doc.get_uri(), Html: follow});                  
                    allSitesJson.push(siteJson);
            });          
            $scope.Favsites = allSitesJson;
            $scope.fnUnfollowSite = fnUnfollowSite;
            $scope.$apply();
            $('#pnlFavoriteSites').text("Favorite Sites");                            

            if (allSitesJson.length == 0) {                  
                $("#divFSErrorMsg").html("<span style='font-size:16px;display:block'>You are not following any site.</span><span style='display:block'>Following a site makes it easier to find it. Simply click the star icon on any site to start following it</span>")
            }
            if (allSitesJson.length > 20) {
                $("#seeAllDiv").show();
            }
            else {
                $("#seeAllDiv").hide();
            }

        }

        , function (sender, args) {
            console.log("Error: " + args.get_message());
        });       
    }`
2

This is currently not possible using OOTB SharePoint REST/JSOM APIs.

However, you can make use of the undocumented REST API endpoint /_vti_bin/homeapi.ashx/sites/followed?mostRecentFirst=true&start=0&count=100&fillSiteData=true to fetch data about followed sites. This endpoint gives you both, classic and modern, followed sites.

Since this is undocumented and unsupported, please be careful while using it as it may stop at some point in the future. FYI - this endpoint is also used in the /_layouts/15/sharepoint.aspx page to show these sites.

Usage:

Using jQuery:

$.ajax({
  url: _spPageContextInfo.siteAbsoluteUrl + "/_vti_bin/homeapi.ashx/sites/followed?mostRecentFirst=true&start=0&count=100&fillSiteData=true",
  type: "GET",  
  headers: { "Accept": "application/json; odata=verbose" },
  success: function(data){
    //do some stuff with data
    console.log(data);
  },
  error: function(data){
    console.log(data);
  },
});

Using AngularJS 1.6.x

var req = {
 method: "GET",
 url: _spPageContextInfo.siteAbsoluteUrl + "/_vti_bin/homeapi.ashx/sites/followed?mostRecentFirst=true&start=0&count=100&fillSiteData=true",
 headers: { "Accept": "application/json; odata=verbose" } 
}

$http(req).then(function(data){
    //bind values from data to html
    console.log(data);
}, function(error){
    console.log(error);
});

Reference - Following O365 sites

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.