🔍 Code Extractor

class SocialAnnouncementManager

Maturity: 49

A SharePoint API manager class for retrieving and managing social announcement tiles displayed on SharePoint sites.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/announcement_manager.py
Lines:
8 - 33
Complexity:
moderate

Purpose

This class provides functionality to interact with SharePoint's Social Announcement system, specifically for retrieving currently active announcement tiles. It inherits from Entity and acts as a service manager for SharePoint announcement operations. The primary use case is fetching announcement data (title, description, images, links) that are displayed as tiles on SharePoint sites. This is typically used in SharePoint integrations where you need to programmatically access site announcements.

Source Code

class SocialAnnouncementManager(Entity):
    """Contains methods related to SharePoint Announcement Tiles"""

    @staticmethod
    def get_current_announcements(context, url):
        """
        Gets the currently active announcements for a given site and returns them as a list of TileData objects.
        Announcement details are stored in Title, Description, BackgroundImageLocation, and LinkLocation properties
        of the TileData.

        :type context: office365.sharepoint.client_context.ClientContext
        :param str url:
        """
        return_type = ClientResult(context, ClientValueCollection(TileData))
        manager = SocialAnnouncementManager(context)
        params = {"url": url}
        qry = ServiceOperationQuery(
            manager, "GetCurrentAnnouncements", params, None, None, return_type
        )
        qry.static = True
        context.add_query(qry)
        return return_type

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

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

context: An office365.sharepoint.client_context.ClientContext instance that provides the authenticated connection to SharePoint and manages the request/response lifecycle. This is required for all SharePoint API operations and contains authentication credentials and site URL information.

Return Value

The class constructor returns a SocialAnnouncementManager instance. The get_current_announcements static method returns a ClientResult object containing a ClientValueCollection of TileData objects. Each TileData object contains announcement details including Title, Description, BackgroundImageLocation, and LinkLocation properties. The ClientResult is a deferred result that will be populated when the context executes the query.

Class Interface

Methods

get_current_announcements(context: ClientContext, url: str) -> ClientResult static

Purpose: Retrieves all currently active announcement tiles for a specified SharePoint site URL

Parameters:

  • context: ClientContext instance providing authenticated connection to SharePoint
  • url: The SharePoint site URL to retrieve announcements from

Returns: ClientResult containing a ClientValueCollection of TileData objects. Each TileData contains Title, Description, BackgroundImageLocation, and LinkLocation properties for an announcement tile. The result is populated after calling context.execute_query().

entity_type_name() -> str property

Purpose: Returns the SharePoint internal entity type name used for API routing and identification

Returns: String 'SP.Social.SocialAnnouncementManager' representing the SharePoint entity type

Attributes

Name Type Description Scope
_context ClientContext Inherited from Entity base class. Stores the SharePoint client context used for API operations instance

Dependencies

  • office365-rest-python-client

Required Imports

from office365.runtime.client_result import ClientResult
from office365.runtime.client_value_collection import ClientValueCollection
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
from office365.sharepoint.webparts.tile_data import TileData
from office365.sharepoint.client_context import ClientContext

Usage Example

from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.social.announcement_manager import SocialAnnouncementManager

# Setup authentication and context
site_url = 'https://contoso.sharepoint.com/sites/mysite'
credentials = UserCredential('username@contoso.com', 'password')
ctx = ClientContext(site_url).with_credentials(credentials)

# Get current announcements for the site
announcements_result = SocialAnnouncementManager.get_current_announcements(ctx, site_url)
ctx.execute_query()

# Access the announcement data
for announcement in announcements_result.value:
    print(f"Title: {announcement.Title}")
    print(f"Description: {announcement.Description}")
    print(f"Image: {announcement.BackgroundImageLocation}")
    print(f"Link: {announcement.LinkLocation}")

Best Practices

  • Always call ctx.execute_query() after calling get_current_announcements to actually execute the query and populate the result
  • The get_current_announcements method is static, so you don't need to instantiate the class to use it - call it directly on the class
  • Ensure the ClientContext is properly authenticated before making any calls
  • Handle potential exceptions from SharePoint API calls (network errors, authentication failures, permission issues)
  • The url parameter should be a valid SharePoint site URL where announcements are configured
  • The returned ClientResult.value will be None until execute_query() is called on the context
  • This class follows the SharePoint REST API pattern where queries are batched and executed together for efficiency
  • The entity_type_name property returns the SharePoint internal type name used for API routing

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class AnnouncementsController 72.8% similar

    A controller class for managing SharePoint Publishing announcements, inheriting from Entity to provide access to announcement-related operations.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/publishing/announcements/controller.py
  • class AnnouncementsData 68.1% similar

    AnnouncementsData is a data class representing SharePoint Publishing announcements data, inheriting from ClientValue to provide client-side value object functionality.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/publishing/announcements/data.py
  • class MicrofeedManager 63.9% similar

    MicrofeedManager is a SharePoint entity class that manages microfeed functionality, inheriting from the Entity base class and representing the SP.Microfeed.MicrofeedManager resource in SharePoint.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/microfeed/manager.py
  • class WebSharingManager 62.9% similar

    A SharePoint entity class that serves as a placeholder for web sharing management methods, representing the SP.Sharing.WebSharingManager entity type in SharePoint's REST API.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/web_sharing_manager.py
  • class SocialRestFeedManager 62.8% 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
← Back to Browse