🔍 Code Extractor

class SocialRestFollowingManager

Maturity: 47

A SharePoint Social REST API manager class that provides methods for managing a user's list of followed actors, including users, documents, sites, and tags, as well as retrieving followers.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/following/rest_manager.py
Lines:
9 - 35
Complexity:
moderate

Purpose

This class serves as a client-side interface to SharePoint's Social REST API for managing social following relationships. It allows applications to retrieve a user's followers, access the current user's social actor representation, and manage following relationships. The class inherits from Entity and integrates with the Office365 REST API framework to execute queries against SharePoint's social features.

Source Code

class SocialRestFollowingManager(Entity):
    """Provides methods for managing a user's list of followed actors (users, documents, sites, and tags)."""

    def __init__(self, context, resource_path=None):
        if resource_path is None:
            resource_path = ResourcePath("SP.Social.SocialRestFollowingManager")
        super(SocialRestFollowingManager, self).__init__(context, resource_path)

    def followers(self):
        """The Followers method retrieves the current user's list of followers. For details on the SocialActor type,
        see section 3.1.5.3."""
        return_type = ClientResult(self.context, ClientValueCollection(SocialActor))
        qry = ServiceOperationQuery(self, "Followers", None, None, None, return_type)
        self.context.add_query(qry)
        return return_type

    @property
    def my(self):
        """The My method gets a SocialRestActor object that represents the current user. See section 3.1.5.35 for
        details on the SocialRestActor type."""
        return SocialRestFollowingManager(
            self.context, ResourcePath("My", self.resource_path)
        )

    @property
    def entity_type_name(self):
        return "SP.Social.SocialRestFollowingManager"

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

context: The client context object that maintains the connection to the SharePoint server and handles authentication. This is required for all API operations and query execution.

resource_path: Optional ResourcePath object specifying the API endpoint. If None, defaults to 'SP.Social.SocialRestFollowingManager'. This allows for custom resource paths when accessing nested or related resources.

Return Value

Instantiation returns a SocialRestFollowingManager object configured with the provided context and resource path. The followers() method returns a ClientResult containing a ClientValueCollection of SocialActor objects representing the current user's followers. The my property returns a new SocialRestFollowingManager instance configured to access the current user's social actor data.

Class Interface

Methods

__init__(self, context, resource_path=None)

Purpose: Initializes the SocialRestFollowingManager with a client context and optional resource path

Parameters:

  • context: The client context object for SharePoint API communication
  • resource_path: Optional ResourcePath object; defaults to 'SP.Social.SocialRestFollowingManager' if None

Returns: None (constructor)

followers(self) -> ClientResult

Purpose: Retrieves the current user's list of followers as SocialActor objects

Returns: ClientResult containing a ClientValueCollection of SocialActor objects representing followers. The actual data is populated after context.execute_query() is called.

@property my(self) -> SocialRestFollowingManager property

Purpose: Gets a SocialRestActor object representing the current user by returning a new SocialRestFollowingManager instance with a 'My' resource path

Returns: A new SocialRestFollowingManager instance configured to access the current user's social actor data

@property entity_type_name(self) -> str property

Purpose: Returns the SharePoint entity type name for this class

Returns: String 'SP.Social.SocialRestFollowingManager' identifying the SharePoint entity type

Attributes

Name Type Description Scope
context ClientContext The client context object inherited from Entity base class, used for executing queries against SharePoint instance
resource_path ResourcePath The resource path object inherited from Entity base class, specifying the API endpoint for this manager 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.rest_following_manager import SocialRestFollowingManager

# Authenticate and create context
ctx = ClientContext('https://yourtenant.sharepoint.com')
ctx.with_credentials(user_credentials)

# Create following manager instance
following_mgr = SocialRestFollowingManager(ctx)

# Get current user's followers
followers_result = following_mgr.followers()
ctx.execute_query()

# Access the followers data
for follower in followers_result.value:
    print(f"Follower: {follower.Name}")

# Access current user's social actor
my_actor = following_mgr.my
ctx.load(my_actor)
ctx.execute_query()

Best Practices

  • Always call ctx.execute_query() after calling followers() to actually execute the query and retrieve data from SharePoint
  • The context object must be properly authenticated before instantiating this class
  • Use the my property to access the current user's social actor information rather than creating separate queries
  • Handle potential authentication errors and network failures when executing queries
  • The followers() method returns a ClientResult that only contains data after execute_query() is called on the context
  • This class is designed for read operations; modifications to following relationships may require additional methods or classes
  • Ensure the SharePoint environment has Social features enabled before using this class

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class SocialFollowingManager 89.2% similar

    SocialFollowingManager manages a user's social following relationships in SharePoint, including followers, followed actors (users, documents, sites, tags), and follow suggestions.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/following/manager.py
  • class SocialRestFeedManager 76.1% similar

    SocialRestFeedManager is a REST API manager class for SharePoint social features, enabling operations like creating posts, modifying threads, and consuming feeds on behalf of the current user.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/feed/rest_manager.py
  • class FollowedContent 71.5% similar

    The FollowedContent class provides access to followed content items in SharePoint user profiles, allowing server-side management of followed items and retrieval of followed content URLs.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/userprofiles/followed_content.py
  • class SocialRestActor 69.3% similar

    SocialRestActor is a class representing an actor (user, document, site, or tag) retrieved from a SharePoint server via OData REST requests.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/rest_actor.py
  • class PeopleManager 69.3% similar

    PeopleManager is a SharePoint client class that provides comprehensive methods for managing user profiles, social following relationships, OneDrive quotas, and user profile properties in SharePoint Online.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/userprofiles/people_manager.py
← Back to Browse