class SocialFollowingManager
SocialFollowingManager manages a user's social following relationships in SharePoint, including followers, followed actors (users, documents, sites, tags), and follow suggestions.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/following/manager.py
9 - 36
moderate
Purpose
This class provides an interface to SharePoint's social following functionality, allowing applications to retrieve information about who follows the current user and get suggestions for actors the user might want to follow. It extends the Entity base class and operates within a SharePoint context, using service operation queries to interact with the SharePoint Social API. The class is designed for read-only operations to query social relationships and suggestions.
Source Code
class SocialFollowingManager(Entity):
"""The SocialFollowingManager class provides properties and methods for managing a user's list of followed actors.
Actors can be users, documents, sites, and tags."""
def __init__(self, context):
super(SocialFollowingManager, self).__init__(
context, ResourcePath("SP.Social.SocialFollowingManager")
)
def get_followers(self):
"""
The GetFollowers method returns the users who are followers of the current user.
"""
return_type = ClientResult(self.context, ClientValueCollection(SocialActor))
qry = ServiceOperationQuery(self, "GetFollowers", None, None, None, return_type)
self.context.add_query(qry)
return return_type
def get_suggestions(self):
"""
The GetSuggestions method returns a list of actors that are suggestions for the current user to follow.
"""
return_type = ClientResult(self.context, ClientValueCollection(SocialActor))
qry = ServiceOperationQuery(
self, "GetSuggestions", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
context: A SharePoint client context object that provides the connection and authentication to the SharePoint environment. This context is used to execute queries and manage the communication with SharePoint services. It must be a valid, authenticated context with appropriate permissions to access social following data.
Return Value
Instantiation returns a SocialFollowingManager object configured with the provided context and a ResourcePath pointing to 'SP.Social.SocialFollowingManager'. The get_followers() and get_suggestions() methods both return ClientResult objects containing ClientValueCollection of SocialActor objects, which represent the followers or suggested actors respectively. These results are populated asynchronously when the context executes the queued queries.
Class Interface
Methods
__init__(self, context) -> None
Purpose: Initializes a new SocialFollowingManager instance with the provided SharePoint context
Parameters:
context: SharePoint client context object providing authentication and connection to SharePoint services
Returns: None - constructor initializes the instance
get_followers(self) -> ClientResult
Purpose: Retrieves the list of users who are followers of the current user
Returns: ClientResult object containing a ClientValueCollection of SocialActor objects representing the followers. The result is populated after calling context.execute_query()
get_suggestions(self) -> ClientResult
Purpose: Retrieves a list of actors (users, documents, sites, tags) that are suggested for the current user to follow
Returns: ClientResult object containing a ClientValueCollection of SocialActor objects representing the suggested actors. The result is populated after calling context.execute_query()
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The SharePoint client context inherited from Entity base class, used to execute queries and manage communication with SharePoint | instance |
resource_path |
ResourcePath | The resource path pointing to 'SP.Social.SocialFollowingManager' endpoint in SharePoint, inherited from Entity base class | instance |
Dependencies
office365
Required Imports
from office365.runtime.client_result import ClientResult
from office365.runtime.client_value_collection import ClientValueCollection
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
from office365.sharepoint.social.actor import SocialActor
Usage Example
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.social.following_manager import SocialFollowingManager
# Authenticate and create context
site_url = 'https://yourtenant.sharepoint.com/sites/yoursite'
username = 'user@yourtenant.onmicrosoft.com'
password = 'your_password'
ctx = ClientContext(site_url).with_credentials(username, password)
# Create SocialFollowingManager instance
following_manager = SocialFollowingManager(ctx)
# Get followers of current user
followers_result = following_manager.get_followers()
ctx.execute_query()
# Access the followers
for follower in followers_result.value:
print(f"Follower: {follower.Name}, Type: {follower.ActorType}")
# Get follow suggestions
suggestions_result = following_manager.get_suggestions()
ctx.execute_query()
# Access the suggestions
for suggestion in suggestions_result.value:
print(f"Suggested: {suggestion.Name}, Type: {suggestion.ActorType}")
Best Practices
- Always call ctx.execute_query() after calling get_followers() or get_suggestions() to actually execute the queued queries and populate the results
- The methods return ClientResult objects that are populated asynchronously, so access the .value property only after execute_query() completes
- Ensure the context has valid authentication before creating the SocialFollowingManager instance
- Handle potential exceptions from execute_query() such as authentication failures or permission issues
- The current user context is determined by the credentials used in the ClientContext, not passed as a parameter
- Multiple queries can be batched by calling multiple methods before execute_query() for better performance
- Check that SharePoint Social Features are enabled on the target site before using this class
- The class is read-only for followers and suggestions; use other SharePoint Social APIs for follow/unfollow operations
- SocialActor objects in results contain properties like Name, ActorType, AccountName, and ImageUri for display purposes
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class SocialRestFollowingManager 89.2% similar
-
class PeopleManager 71.9% similar
-
class MySiteRecommendations 69.0% similar
-
class SocialRestFeedManager 68.9% similar
-
class FollowedContent 68.5% similar