Twitter autopost not working

adam wright asked on December 1, 2014 13:45

I am using the social marketing api to schedule and send tweets

i was using 8.1.3 but the code was firing the schedule task but was not showing up in twitter or producing and error so i upgraded to the latest hotfix 8.1.14. This now doesn't create a schedule task at all and immediatly posts my tweet to twitter!

here is the code

void Control_OnAfterSave(object sender, EventArgs e) { JobInfo job = Control.EditedObject as JobInfo;

    #region Tweet

    TwitterPostInfo twitterPost = new TwitterPostInfo();

    TwitterAccountInfo defaultTwitterAccountInfo = TwitterAccountInfoProvider.GetDefaultTwitterAccount(SiteContext.CurrentSiteID);

    if (defaultTwitterAccountInfo != null)
    {
        twitterPost.TwitterPostTwitterAccountID = defaultTwitterAccountInfo.TwitterAccountID;
    }

    //Get the Location and Contract types
    LocationInfo location = LocationInfoProvider.GetLocationInfo(job.LocationID);
    ContractInfo contract = ContractInfoProvider.GetContractInfo(job.ContractID);

    //Create url
    string url = String.Format("http://{0}/{1}/{2}/{3}", SiteContext.CurrentSite.DomainName, Constants.ALIASPATH_JOBLISTINGS, job.ReferenceNo, job.JobTitle.ToSlug());

    //Create Twwet
    twitterPost.TwitterPostText = String.Format("{0}, {1} in {2} {3}", contract.Name, job.JobTitle, location.Name, url);
    twitterPost.TwitterPostURLShortenerType = URLShortenerTypeEnum.TinyURL;
    twitterPost.TwitterPostScheduledPublishDateTime = job.PostDate;
    twitterPost.TwitterPostSiteID = SiteContext.CurrentSiteID;
    twitterPost.TwitterPostID = job.ID;

    //Send Tweet
    TwitterPostInfoProvider.SetTwitterPostInfo(twitterPost);
    TwitterPostInfoProvider.PublishTwitterPost(twitterPost.TwitterPostID);

    string message = TwitterPostInfoProvider.GetPostPublishStateMessage(twitterPost, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite);

    #endregion

}

Correct Answer

Timothy Fenton answered on December 2, 2014 22:23

Hello Adam!

Thank you for the help Brenden!

We solved this issue through a ticket, the cause for this issue is that they are using UK formatted DateTime and the twitter API was switching the day and month ( using US formatted DateTime ), and since we are December it will think you are talking about Feb 12 instead of Dec 2. The solution for this was to do one of the following:

  1. Convert the DateTime to use formatted DateTime and feed assign it to the twitter post or
  2. Just do a semi-hard-coded solution by creating a new DateTime and switch the parameters of day and month in the constructor so that it would assign it to the correct time.

Thanks!

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on December 2, 2014 13:55

There are some options with the Twitter Autopost control which will do this automatically for you. Are you checking the box to "Create a tweet when you save the page" AS WELL AS setting either a "Publish time" or checking the "Post tweet after page is published" box and setting a "Publish from" date?

There should be no reason to write code around this functionality as it already exists. Also, from what I've looked at there isn't a scheduled task to publish or post to Twitter in v8, so maybe that was some remnant of a v7 upgrade?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.