Пример #1
0
    /// <summary>
    /// Gets and updates Facebook post. Called when the "Get and update post" button is pressed.
    /// Expects the CreateFacebookPost method to be run first.
    /// </summary>
    private bool GetAndUpdateFacebookPost()
    {
        // Get an page to which the post is tied
        FacebookAccountInfo page = FacebookAccountInfoProvider.GetFacebookAccountInfo("MyNewPage", SiteContext.CurrentSiteID);

        if (page == null)
        {
            throw new Exception("[FacebookApiExamples.GetAndUpdateFacebookPost]: Page 'My new page' wasn't found.");
        }

        // Get the Facebook post from DB
        FacebookPostInfo post = FacebookPostInfoProvider.GetFacebookPostInfosByAccountId(page.FacebookAccountID).FirstOrDefault();

        if (post != null)
        {
            // Update the properties
            post.FacebookPostText = post.FacebookPostText + " Edited.";

            // Save the changes into DB
            FacebookPostInfoProvider.SetFacebookPostInfo(post);

            return(true);
        }

        return(false);
    }
Пример #2
0
    /// <summary>
    /// Deletes Facebook post. Called when the "Delete post" button is pressed.
    /// Expects the CreateFacebookPost method to be run first.
    /// </summary>
    private bool DeleteFacebookPosts()
    {
        // Get an page to which the post is tied
        FacebookAccountInfo page = FacebookAccountInfoProvider.GetFacebookAccountInfo("MyNewPage", SiteContext.CurrentSiteID);

        if (page == null)
        {
            throw new Exception("[FacebookApiExamples.DeleteFacebookPosts]: Page 'My new page' wasn't found.");
        }

        // Get the Facebook post from DB
        ObjectQuery <FacebookPostInfo> post = FacebookPostInfoProvider.GetFacebookPostInfosByAccountId(page.FacebookAccountID);

        // Delete the Facebook post from CMS and from Facebook
        foreach (FacebookPostInfo deletePost in post)
        {
            FacebookPostInfoProvider.DeleteFacebookPostInfo(deletePost);
        }

        return(post.Count != 0);
    }
Пример #3
0
    /// <summary>
    /// Publishes a facebook post.
    /// </summary>
    private bool PublishPostToFacebook()
    {
        // Get an page to which the post is tied
        FacebookAccountInfo page = FacebookAccountInfoProvider.GetFacebookAccountInfo("MyNewPage", SiteContext.CurrentSiteID);

        if (page == null)
        {
            throw new Exception("[FacebookApiExamples.PublishPostToFacebook]: Page 'My new page' wasn't found.");
        }

        // Get the Facebook post from DB
        FacebookPostInfo post = FacebookPostInfoProvider.GetFacebookPostInfosByAccountId(page.FacebookAccountID).FirstOrDefault();

        if (post == null)
        {
            throw new Exception("[FacebookApiExamples.PublishPostToFacebook]: No post has been created via these api Examples, or they have been deleted.");
        }

        // Publish the post. The post is scheduled to be published if its FacebookPostScheduledPublishDateTime is set in the future.
        FacebookPostInfoProvider.PublishFacebookPost(post.FacebookPostID);

        return(true);
    }