class MySiteRecommendations
A SharePoint Portal class that manages site and document recommendations for the current user, providing methods to follow or unfollow content items.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/portal/mysite_recommendations.py
6 - 63
moderate
Purpose
This class serves as a manager for SharePoint MySite recommendations functionality. It provides static methods to follow and stop following documents or sites in SharePoint, integrating with the SharePoint Portal's recommendation system. The class inherits from Entity and is designed to work with SharePoint's client context to execute service operations for managing followed content.
Source Code
class MySiteRecommendations(Entity):
"""Provides a method to get site and document recommendations for the current user, and methods to follow or
stop following a particular item."""
@staticmethod
def follow_item(context, uri, personal_site_uri, category):
"""
The FollowItem method adds the specified document or site to the list of followed content (as described in
[MS-SOCCSOM] section 3.1.5.38.2.1.1). FollowItem MUST return TRUE if successful or FALSE if not successful.
:type context: office365.sharepoint.client_context.ClientContext
:param str uri: URL that identifies the item to follow.
:param str personal_site_uri: Specifies the location of the personal site of the current user on the farm.
:param str category: Specifies the type of the item to follow.
"""
return_type = ClientResult(context)
payload = {
"uri": uri,
"personalSiteUri": personal_site_uri,
"category": category,
}
manager = MySiteRecommendations(context)
qry = ServiceOperationQuery(
manager, "FollowItem", None, payload, None, return_type
)
qry.static = True
context.add_query(qry)
return return_type
@staticmethod
def stop_following_item(context, uri, personal_site_uri, category):
"""
The StopFollowingItem method removes the specified document or site from list of followed content (as described
in [MS-SOCCSOM] section 3.1.5.38.2.1.6). StopFollowingItem MUST return TRUE if successful or FALSE if
not successful.
:type context: office365.sharepoint.client_context.ClientContext
:param str uri: URL that identifies the item to stop following.
:param str personal_site_uri: Specifies the location of the personal site of the current user on the farm.
:param str category: Specifies the type of the item to follow.
"""
return_type = ClientResult(context)
payload = {
"uri": uri,
"personalSiteUri": personal_site_uri,
"category": category,
}
manager = MySiteRecommendations(context)
qry = ServiceOperationQuery(
manager, "StopFollowingItem", None, payload, None, return_type
)
qry.static = True
context.add_query(qry)
return return_type
@property
def entity_type_name(self):
return "Microsoft.SharePoint.Portal.MySiteRecommendations"
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
context: An instance of office365.sharepoint.client_context.ClientContext that provides the connection and authentication context for SharePoint operations. This is required for all operations and is passed to the parent Entity class constructor.
Return Value
Instantiation returns a MySiteRecommendations object that inherits from Entity. The static methods (follow_item and stop_following_item) return a ClientResult object containing a boolean value - TRUE if the operation was successful, FALSE otherwise. The entity_type_name property returns the string 'Microsoft.SharePoint.Portal.MySiteRecommendations'.
Class Interface
Methods
follow_item(context: ClientContext, uri: str, personal_site_uri: str, category: str) -> ClientResult
static
Purpose: Adds the specified document or site to the list of followed content for the current user
Parameters:
context: ClientContext instance providing SharePoint connection and authenticationuri: URL that identifies the item to follow (document or site URL)personal_site_uri: Location of the personal site of the current user on the SharePoint farmcategory: Type of the item to follow (e.g., 'Document' or 'Site')
Returns: ClientResult object containing a boolean value - TRUE if successful, FALSE if not successful. The value is accessible after calling context.execute_query()
stop_following_item(context: ClientContext, uri: str, personal_site_uri: str, category: str) -> ClientResult
static
Purpose: Removes the specified document or site from the list of followed content for the current user
Parameters:
context: ClientContext instance providing SharePoint connection and authenticationuri: URL that identifies the item to stop following (document or site URL)personal_site_uri: Location of the personal site of the current user on the SharePoint farmcategory: Type of the item to stop following (e.g., 'Document' or 'Site')
Returns: ClientResult object containing a boolean value - TRUE if successful, FALSE if not successful. The value is accessible after calling context.execute_query()
entity_type_name() -> str
property
Purpose: Returns the SharePoint entity type name for this class
Returns: String value 'Microsoft.SharePoint.Portal.MySiteRecommendations' representing the SharePoint entity type
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
_entity_type_name |
str | Internal storage for the SharePoint entity type name, accessed via the entity_type_name property | instance |
Dependencies
office365-runtimeoffice365-sharepoint
Required Imports
from office365.runtime.client_result import ClientResult
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
from office365.sharepoint.client_context import ClientContext
Usage Example
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.portal.my_site_recommendations import MySiteRecommendations
# Setup SharePoint context with authentication
ctx = ClientContext('https://yourtenant.sharepoint.com')
ctx = ctx.with_credentials(UserCredential('username', 'password'))
# Follow a document
uri = 'https://yourtenant.sharepoint.com/sites/team/Documents/file.docx'
personal_site_uri = 'https://yourtenant-my.sharepoint.com/personal/user'
category = 'Document'
result = MySiteRecommendations.follow_item(ctx, uri, personal_site_uri, category)
ctx.execute_query()
if result.value:
print('Successfully followed the item')
else:
print('Failed to follow the item')
# Stop following a site
site_uri = 'https://yourtenant.sharepoint.com/sites/team'
site_category = 'Site'
result = MySiteRecommendations.stop_following_item(ctx, site_uri, personal_site_uri, site_category)
ctx.execute_query()
if result.value:
print('Successfully unfollowed the item')
Best Practices
- Always call ctx.execute_query() after calling follow_item or stop_following_item to execute the queued operation
- Ensure the ClientContext is properly authenticated before using any methods
- Verify that the personal_site_uri is valid and accessible for the current user
- Use appropriate category values ('Document' or 'Site') based on the item type being followed
- Check the return value (result.value) after executing the query to verify operation success
- The class uses static methods, so instantiation is handled internally - users should call methods directly on the class
- URIs must be valid, fully-qualified SharePoint URLs
- The class is stateless - each method call is independent and doesn't maintain state between calls
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class SocialFollowingManager 69.0% similar
-
class MySiteLinks 67.1% similar
-
class PromotedSites 63.2% similar
-
class SocialRestFollowingManager 62.3% similar
-
class FollowedContent 62.3% similar