Question

I try to follow a page with JavaScript Object Model. My solution is based on many examples in the web and should work...

var siteActorInfo = new SP.Social.SocialActorInfo();        
siteActorInfo.set_contentUri(siteInfo.Url);
siteActorInfo.set_accountName(accountName);
siteActorInfo.set_actorType(4);

if (siteInfo.Followed)
    followingManager.follow(siteActorInfo);
else
    followingManager.stopFollowing(siteActorInfo);

clientContext.executeQueryAsync(function () {
    if (onSuccess) onSuccess();
}, function (a,error) {
    if (onError) onError(error.get_message());
});

But when I try to follow or unfollow the page, I get this error:

Specified argument was out of the range of valid values. Parameter name: actor.ActorType

The SP.Social.SocialFollowingManager is initialized in another function and generally works.

It was not a problem to retrieve the list of followed sites.

I don't understand, whats the problem here.

Instead of 4 I also tried SP.Social.SocialActorTypes.sites, but this makes, no difference of course, because the value of the property is 4.

Was it helpful?

Solution

You can isolate the problem by trying to execute below in Console and check if error is still appearing

var context = SP.ClientContext.get_current();
var socialManager = new SP.Social.SocialFollowingManager(context);
var socialSite = new SP.Social.SocialActorInfo();
socialSite.set_contentUri("https://siteurl");
socialSite.set_actorType(SP.Social.SocialActorType.site);
socialManager.follow(socialSite);

context.executeQueryAsync(
    function() { alert('Sites followed!'); },
    function(sender, args) { alert('Error: ' + args.get_message()); });
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top