🔍 Code Extractor

class SocialPostCreationData

Maturity: 52

A data class representing the content structure for creating social media posts in SharePoint's SocialFeedManager, supporting text with substitution references for mentions, tags, and links.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/posts/creation_data.py
Lines:
4 - 29
Complexity:
simple

Purpose

SocialPostCreationData is a ClientValue-based class designed to encapsulate the content and metadata for creating social posts in SharePoint Online. It provides a structured way to define post content with support for dynamic substitution of social elements (mentions, tags, links) through a placeholder-based system. The class is primarily used as a parameter object for the SocialFeedManager.CreatePost method, enabling rich social interactions with formatted text, user mentions (prefixed with @), and hashtags (prefixed with #).

Source Code

class SocialPostCreationData(ClientValue):
    """
    The SocialPostCreationData object specifies the content of a post in the SocialFeedManager.CreatePost method
    (see section 3.1.5.19.2.1.1). The post consists of a text message, which can optionally include social tags,
    mentions of users, and links.
    """

    def __init__(self, content_text=None):
        """
        :param str content_text: The ContentText string contains the text body of the post. It can optionally contain
            one or more substitution references to elements in the zero-based SocialDataItems array. A substitution
            reference consists of a series of characters that consist of an open-brace character ({) followed by one
            of more digits in the range 0 to 9 and terminated by a close-brace character (}).
            The substitution reference is replaced by the text value of the element in the in the array at the offset
            specified by the value of the digits. For example, the text string "{0}" is replaced by the first element
            in the SocialDataItems array.
            Although it is not required by this interchange protocol, substitution references to mentions can be
            preceded by an at sign (@) in the ContentText and substitution references to social tags can be preceded
            by a hash mark (#) in the ContentText. The at sign and hash mark are not required by the protocol but are
            helpful if the post is displayed to a user by a client.
        """
        self.ContentText = content_text

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

Parameters

Name Type Default Kind
bases ClientValue -

Parameter Details

content_text: Optional string containing the text body of the post. Supports substitution references in the format '{n}' where n is a zero-based index into a SocialDataItems array. These references are replaced with actual values at runtime. Mentions can be preceded by '@' and tags by '#' for better user display, though these prefixes are not protocol-required. Example: 'Hello {0}, check out #{1}' where {0} might reference a user mention and {1} a hashtag.

Return Value

Instantiation returns a SocialPostCreationData object with the ContentText attribute set to the provided content_text parameter (or None if not provided). The entity_type_name property returns the string 'SP.Social.SocialPostCreationData', which is used for serialization and protocol identification in SharePoint API communications.

Class Interface

Methods

__init__(self, content_text=None) -> None

Purpose: Initializes a new SocialPostCreationData instance with optional post content text

Parameters:

  • content_text: Optional string containing the post text body with optional substitution references in format '{n}' for dynamic content replacement

Returns: None - constructor initializes the instance

@property entity_type_name(self) -> str property

Purpose: Returns the SharePoint entity type identifier used for protocol serialization and API communication

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

Attributes

Name Type Description Scope
ContentText str or None The text body of the social post, optionally containing substitution references in format '{n}' that map to elements in a SocialDataItems array. Can include @ prefixes for mentions and # prefixes for hashtags. instance

Dependencies

  • office365

Required Imports

from office365.runtime.client_value import ClientValue

Usage Example

from office365.runtime.client_value import ClientValue
from office365.sharepoint.social.post_creation_data import SocialPostCreationData

# Create a simple post
post_data = SocialPostCreationData(content_text="Hello, this is my first post!")

# Create a post with substitution references for mentions and tags
post_with_mentions = SocialPostCreationData(
    content_text="Hey @{0}, check out this #{1} topic!"
)

# Access the entity type name for serialization
entity_type = post_with_mentions.entity_type_name  # Returns 'SP.Social.SocialPostCreationData'

# The ContentText attribute can be accessed or modified
post_data.ContentText = "Updated post content"
print(post_data.ContentText)

# Typically used with SocialFeedManager.CreatePost method
# social_feed_manager.create_post(post_data)

Best Practices

  • Always validate content_text for proper substitution reference format (matching braces and valid indices) before passing to CreatePost
  • Use '@' prefix for user mentions and '#' prefix for hashtags in ContentText for better user experience, even though not protocol-required
  • Ensure substitution references (e.g., {0}, {1}) correspond to valid indices in the accompanying SocialDataItems array
  • Keep ContentText concise and within SharePoint's post length limits
  • The class is immutable after creation except for the ContentText attribute, which can be modified directly
  • This class is designed to be used as a parameter object, not for long-term state storage
  • The entity_type_name property should not be modified as it's used for SharePoint protocol serialization
  • When using substitution references, maintain consistency between the number of references and the size of the SocialDataItems array to avoid runtime errors

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class SocialPostDefinitionData 78.5% similar

    A data class representing additional information about server-generated social media posts in SharePoint/Office 365, specifically designed for server-to-server communication.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/posts/definition_data.py
  • class SocialPost 76.9% similar

    SocialPost is a data class that represents a social media post retrieved from a SharePoint server, encapsulating post content, attachments, overlays, source information, and user engagement data.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/posts/post.py
  • class SocialPostDefinitionDataItem 72.0% similar

    A data class representing an item to be inserted in a social media post by replacing a token in the post definition, used exclusively in server-to-server calls within the Office 365 API.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/posts/definition_data_item.py
  • class SocialFeed 71.2% similar

    SocialFeed is a data class representing a social media feed containing threads of posts, with metadata about processed items and unread mentions.

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

    A data class representing site creation information for SharePoint Online tenant administration, including creation count and source GUID.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/administration/sites/creation_data.py
← Back to Browse