0

I am getting issue while fetching follow information for a site. I am getting error when calling isFollow() method. Error is "Invalid Pointer".

below is my code

    function isAlreadyFollowed() {
clientContext = SP.ClientContext.get_current();

socialManager = new SP.Social.SocialFollowingManager(clientContext);
socialActor = new SP.Social.SocialActorInfo();

var siteContentUrl = window.location;
try
{
socialActor.set_contentUri(siteContentUrl);
//alert('hi');
//getting error at below line
var result = socialManager.isFollowed(socialActor);
}
catch(err)
{
alert(err.message);
}
//alert(result);

}

do anyone have any idea regarding this error.

Thanks,

0

The only value you've applied to your socialActor object is URI. What were you hoping to be returned?

You need to apply a valid user to it in order to return true or false from the isFollowed Boolean property. You also need to get it's value.

See the example below which expects a valid username as input. An alert will display the current following status of the logged-in user to the targetUser and follow/unfollow as required.

An email will also be sent to the targetUser. This is a default action.

var clientContext;
var followingManager;
var actorInfo;
var isFollowed;
var followedCount;
var user; // "domain\\user" <- note the double backslash

// Get the Following status of the current user.
function getFollowingStatus(targetUser)
{
    user = targetUser;

    // Get the current client context
    clientContext = SP.ClientContext.get_current();

    // Create a SocialFeedManager instance
    followingManager = new SP.Social.SocialFollowingManager(clientContext);

    // Create a SocialActorInfo object to represent the target user
    actorInfo = new SP.Social.SocialActorInfo();
    actorInfo.set_accountName(user);

    // Find out whether the currently logged-in user is following the target user
    isFollowed = followingManager.isFollowed(actorInfo);

    clientContext.executeQueryAsync(showFollowingStatus, requestFailed)
}

function showFollowingStatus()
{
    // Is following target user
    if (isFollowed.get_value()===true){
        followingManager.stopFollowing(actorInfo);
        alert("You are no longer following " + user);
    }
    // Is not following target user
    else if (isFollowed.get_value()===false) 
    {
        followingManager.follow(actorInfo);
        alert("You are now following " + user);
    }
}

// Failure callback
function requestFailed(sender, args) {
    args.get_message();
}

// Usage getFollowingStatus('domain\\user')

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.