NAV

Publication (Social Media)(Last Updated : 01/04/2017)

Publish content to various social networking platforms, including Facebook and Twitter. Before sending a publication call, you must connect your social networking accounts to your Trumpia account by logging into My Account > Social Networking Accounts. You may add multiple social networking accounts for publishing a status update for any number of accounts.

Methods

PUT /rest/v1/{user_name}/publication
GET /rest/v1/{user_name}/publication/{publication_id}

PUT Publication

Post a status update on Facebook and a tweet on Twitter simultaneously. Privacy for Facebook posts can be set to various levels, including everyone, friends of friends, or friends only. Links, images, or videos can be shared, given the URL. Both Facebook and Twitter posts can be scheduled for a specific date and time.

Resource Information

Response Formats JSON
Allowed Methods PUT
URL http://api.trumpia.com/rest/v1/{user_name}/publication
{user_name} Your account username (this can be found in the Account Settings page after logging in.)

Header Parameters

* required parameters
Parameter Description
Content-Type * application/json
X-Apikey * Your API key (This can be found in the API Settings page after logging in.)

Example value: 123456789abc1011

Body Parameters

* required parameters
Parameter Description
description * Description of your post for your reference.
twitter See Twitter object table.
facebook See Facebook object table.
facebook_page See Facebook Page object table.
post_date Date and time to post the status update. If these values are not provided, the post will be published immediately. Valid format is YYYY-MM-DD hh:mm:ss (ex: 2013-05-29 14:10:32).
Value Description
YYYY four-digit year
MM two-digit month (01=January, etc.)
DD two-digit day of month (01 through 31)
hh two digit hours (00 through 23; am/pm NOT allowed)
mm two digit minutes (00 through 59)
ss two digit seconds (00 through 59)

> Twitter Object

* required parameters
Parameter Description
tweet * Content of Twitter status update. Maximum length is 140 characters.
account_names * Name(s) of the Twitter account(s) to post the tweet to. Multiple accounts can be listed separated by commas.

Note: The account(s) must be linked to your Trumpia account.

> Facebook Object

* required parameters
Parameter Description
post * Content of Facebook status update. Maximum length is 4,000 characters.
account_names * Name(s) of the Facebook account(s) to post the status update to. Multiple accounts can be listed separated by commas.

Note: The account(s) must be linked to your Trumpia account.
privacy Control who can see your message. For more information on Facebook's privacy settings, visit its Data Use Policy page. Only one value may be selected.
Value Description
1 Everyone
3 Friends only
Default value: 1
attachment See Attachment Object table.

> Facebook Page Object

* required parameters
Parameter Description
post * Content of Facebook page status update. Maximum length is 4,000 characters.
account_names * Name(s) of the Facebook account(s) to post the status update to. Multiple accounts can be listed separated by commas.

Note: The account(s) must be linked to your Trumpia account.
attachment See Attachment Object table.

>> Attachment Object

* required parameters
Parameter Description
type * Share media,such as a video or image, or a web link in your status update. Only one value may be selected.
url * Provide the URL to the shared web link or where your video or image is hosted.

Note: The URL must include "http://". Maximum video size is 1024 MB.

Code sample for PUT Publication

"Request Example: In the following example, three types of social-network status updates are submitted simultaneously: Twitter, Facebook, and Facebook Page.

The first parameter value that is required to be set is the description, which serves as a reference to the purpose of the request. Next in the template, a simple Twitter status update, or tweet, is posted to four different Twitter accounts. The following Facebook status update is also posted to four different Facebook accounts; the privacy parameter is set to 1, which allows Everyone to see the post. The post also includes an attachment type of 3, an image, whose web location is provided through the URL parameter. Posting to a Facebook Page is similar, except that in this example, an AVI video is included in the post.

Finally, the post_date, or when these updates are published, is set to May 22, 2013, at 8:00 pm.

PUT http://api.trumpia.com/rest/v1/{username}/publication"
{
  "description" : "This is a description",
  "twitter" :
  {
    "tweet" : "Hello~! Twitter",
    "account_names" : "twitter_acc_01, twitter_acc_02, twitter_acc_03"
  },
  "facebook" :
  {
    "post" : "Hello~! Facebook",
    "account_names" : "fb.account01, fb.account02, fb.account03",
    "privacy" : "1",
    "attachment" :
    {
      "type" : "3",
      "url" : "http://yourdomain.com/image.png"
    }
  },
  "facebook_page" :
  {
    "post" : "Hello~! Facebook Page",
    "account_names" : "fb.page.account01, fb.page.account02, fb.page.account03",
    "attachment" :
    {
      "type" : "4",
      "url" : "http://yourdomain.com/video.avi"
    }
  },
  "post_date" : "2013-05-22 20:00:00"
}

"Response Example:
The request_id and publication_id are returned, which shows that the API request has been successfully submitted. The request_id can be used with a GET Status Report request to retrieve summary result."
{
  "request_id" : "1234561234567asdf123",
  "publication_id" : "987987987987"
}


<?
    // PUT Publication - Publish a status update to your feed on Facebook and/or Twitter.
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/publication";

    $request_data = array(
        "description" => "This is a description",
        "twitter"=>array(
            "tweet" => "Hello~! Twitter",
            "account_names" => "twitter_acc01, twitter_acc02, twitter_acc03, twitter_acc04"
        ),
        "facebook"=>array(
            "post" => "Hello~! Facebook",
            "account_names" => "fb.account01, fb.account02, fb.account03, fb.account04",
            "privacy" => "1",
            "attachment" =>array(
                "type" => "3",
                "url" => "http://yourdomain.com/image.png"
            )
        ),
        "facebook_page"=>array(
            "post" => "Hello~! Facebook Page",
            "account_names" => "fb.page.account01, fb.page.account02, fb.page.account03, fb.page.account04",
            "attachment" =>array(
                "type" => "4",
                "url" => "http://yourdomain.com/video.avi"
            )
        ),
        "post_date" => "2013-05-22 20:00:00"
    );

    $request_rest = new RestRequest();

    $request_rest->setRequestURL($request_url);
    $request_rest->setAPIKey("{api_key}");
    $request_rest->setRequestBody(json_encode($request_data));
    $request_rest->setMethod("PUT");
    $result = $request_rest->execute();

    $response_status = $result[0];
    $json_response_data = $result[1];

    if ($response_status == "200") {	//success
        $response_data = json_decode($json_response_data);
        echo "request_id : " . $response_data->request_id . "<br>";
        echo "publication_id : " . $response_data->publication_id;
    } else {
        echo $response_status ." - connection failure";
    }
?>


// PUT Publication - Publish a status update to your feed on Facebook and/or Twitter.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.json.simple.JSONArray" %>
<%@ page import="org.json.simple.JSONObject" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="java.io.OutputStreamWriter" %>
<%@ page import="java.io.Writer" %>
<%@ page import="java.net.HttpURLConnection" %>
<%@ page import="java.net.URL" %>
<html>
<title>Publication Put Sample Code</title>
<body>

<%
	String username = "username";

	JSONObject twitter = new JSONObject();
	twitter.put("tweet", "Hello~! Twitter");
	twitter.put("account_names", "twitter_acc01, twitter_acc02, twitter_acc03, twitter_acc04");

	JSONObject facebookAttachment = new JSONObject();
	facebookAttachment.put("type", "3");
	facebookAttachment.put("url", "http://yourdomain.com/image.png");

	JSONObject facebook = new JSONObject();
	facebook.put("post", "Hello~! Facebook");
	facebook.put("account_names", "fb.account01, fb.account02, fb.account03, fb.account04");
	facebook.put("privacy", "1");
	facebook.put("attachment", facebookAttachment);

	JSONObject facebookPageAttachment = new JSONObject();
	facebookPageAttachment.put("type", "4");
	facebookPageAttachment.put("url", "http://yourdomain.com/video.avi");

	JSONObject facebookPage = new JSONObject();
	facebookPage.put("post", "Hello~! Facebook Page");
	facebookPage.put("account_names", "fb.page.account01, fb.page.account02, fb.page.account03, fb.page.account04");
	facebookPage.put("attachment", facebookPageAttachment);

	JSONObject publicationPut = new JSONObject();
	publicationPut.put("description", "This is description");
	publicationPut.put("twitter", twitter);
	publicationPut.put("facebook", facebook);
	publicationPut.put("facebook_page", facebookPage);
	publicationPut.put("post_date", "2012-05-22 20:00:00");

	String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/publication";
	URL url = new URL(urlStr);
	HttpURLConnection conn = (HttpURLConnection) url.openConnection();
	conn.setRequestMethod("PUT");
	conn.setDoOutput(true);
	conn.setDoInput(true);
	conn.setUseCaches(false);
	conn.setAllowUserInteraction(false);
	conn.setRequestProperty("Content-type", "application/json");
	conn.setRequestProperty("X-Apikey", "12345aaaaa67890aaaaa");
	OutputStream outPutStream = conn.getOutputStream();
	Writer writer = new OutputStreamWriter(outPutStream, "UTF-8");
	writer.write(messagePut.toJSONString());
	writer.close();
	outPutStream.close();

	if (conn.getResponseCode() != 200) {
%>
	Error : <%=conn.getResponseMessage()%>
<%
	}else{
	// Buffer the result into a string
	BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
	StringBuilder sb = new StringBuilder();
	String line;
	while ((line = rd.readLine()) != null) {
		sb.append(line);
	}
	rd.close();
	conn.disconnect();
%>
	Response : <%=sb.toString()%>
<%
	}
%>
</body>
</html>


// PUT Publication - Publish a status update to your feed on Facebook and/or Twitter.
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace samplecode
{
    class PublicationInfo
    {
        public string description { get; set; }
        public JObject twitter { get; set; }
        public JObject facebook { get; set; }
        public JObject facebook_page { get; set; }
    }
    class Result
    {
        public string request_id { get; set; }
    }
    class PublicationPut
    {
        static void Main()
        {
            RunAsync().Wait();
        }

        static async Task RunAsync()
        {
            using (var client = new HttpClient())
            {
                var apikey = "12345aaaaa67890aaaaa";

                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("X-Apikey", string.Format("{0}", apikey));

                var username = "username";

                //PUT
                JObject twitterData = new JObject();
                twitterData.Add("tweet", "Hello~! Twitter");
                twitterData.Add("account_names", "twitter_acc01, twitter_acc02, twitter_acc03, twitter_acc04");

                JObject attachment = new JObject();
                attachment.Add("type", "3");
                attachment.Add("url", "http://yourdomain.com/image.png");

                JObject facebookData = new JObject();
                facebookData.Add("post", "Hello~! Facebook");
                facebookData.Add("account_names", "fb.account01, fb.account02, fb.account03, fb.account04");
                facebookData.Add("privacy", "1");
                facebookData.Add("attachment", attachment);

                JObject facebookPageData = new JObject();
                facebookPageData.Add("post", "Hello~! Facebook Page");
                facebookPageData.Add("account_names", "fb.page.account01, fb.page.account02, fb.page.account03, fb.page.account04");
                facebookPageData.Add("attachment", attachment);

                var info = new PublicationInfo() { description = "This is a description", twitter = twitterData, facebook = facebookData, facebook_page = facebookPageData };
                Uri postUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/publication", username));
                var response = client.PutAsJsonAsync(postUrl, info).Result;
                if (response.IsSuccessStatusCode)
                {
                    var p = response.Content.ReadAsAsync<Result>().Result;
                    string json = JsonConvert.SerializeObject(p);
                    Console.WriteLine(json);
                }
            }
        }
    }
}

GET Publication

Retrieve the summary results of a PUT Publication request, including the total number of status updates submitted, the number of successful updates, and the number of failed updates.

Resource Information

Response Formats JSON
Allowed Methods GET
URL http://api.trumpia.com/rest/v1/{user_name}/publication/{publication_id}
{user_name} Your account username (this can be found in the Account Settings page after logging in.)
{publication_id} The publication_id being looked up.

Header Parameters

* required parameters
Parameter Description
Content-Type * application/json
X-Apikey * Your API key (This can be found in the API Settings page after logging in.)

Example value: 123456789abc1011

Code sample for GET Publication

"Response Example:
The values of the status parameter can be either scheduled, posting (i.e., in progress) or posted (i.e., completed)."
{
  "status" : "posted",
  "twitter" :
  {
    "total" : 5,
    "posted" : 2,
    "failed" : 3
  },
  "facebook" :
  {
    "total" : 5,
    "posted" : 5,
    "failed" : 0
  },
  "facebook_page" :
  {
    "total" : 5,
    "posted" : 1,
    "failed" : 4
  }
}


<?
    // GET Publication - Retrieve a summary of results for a publication post.
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/publication";
    $publication_id = "987987987987";
    $request_url =	$request_url . "/" . $publication_id;

    $request_rest = new RestRequest();

    $request_rest->setRequestURL($request_url);
    $request_rest->setAPIKey("{api_key}");
    $request_rest->setMethod("GET");
    $result = $request_rest->execute();

    $response_status = $result[0];
    $json_response_data = $result[1];

    if ($response_status == "200") {	//success
        echo $json_response_data;
    } else {
        echo $response_status ." - connection failure";
    }
?>


// GET Publication - Retrieve a summary of results for a publication post.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.json.simple.JSONArray" %>
<%@ page import="org.json.simple.JSONObject" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="java.io.OutputStreamWriter" %>
<%@ page import="java.io.Writer" %>
<%@ page import="java.net.HttpURLConnection" %>
<%@ page import="java.net.URL" %>
<html>
<title>PublicationGetById Sample Code</title>
<body>

<%
	String username = "username";
	String publicationId = "987987987987";
	String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/publication/" + publicationId;

	URL url = new URL(urlStr);
	HttpURLConnection conn = (HttpURLConnection) url.openConnection();
	conn.setRequestProperty("Content-type", "application/json");
	conn.setRequestProperty("X-Apikey", "12345aaaaa67890aaaaa");

	if (conn.getResponseCode() != 200) {
%>
	Error : <%=conn.getResponseMessage()%>
<%
	}else{
	// Buffer the result into a string
	BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
	StringBuilder sb = new StringBuilder();
	String line;
	while ((line = rd.readLine()) != null) {
		sb.append(line);
	}
	rd.close();
	conn.disconnect();
%>
	Response : <%=sb.toString()%>
<%
	}
%>
</body>
</html>


// GET Publication - Retrieve a summary of results for a publication post.
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace samplecode
{
    class PublicationInfo
    {
        public string status { get; set; }
        public JObject twitter { get; set; }
        public JObject facebook { get; set; }
        public JObject facebook_page { get; set; }
    }
    class PublicationDetailGet
    {
        static void Main()
        {
            RunAsync().Wait();
        }

        static async Task RunAsync()
        {
            using (var client = new HttpClient())
            {
                var apikey = "12345aaaaa67890aaaaa";

                client.BaseAddress = new Uri("http://api.trumpia.com");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("X-Apikey", string.Format("{0}", apikey));

                var username = "username";
                var publicationId = "987987987987";

                //GET
                HttpResponseMessage response = await client.GetAsync(string.Format("/rest/v1/{0}/publication/{1}", username, publicationId));
                if (response.IsSuccessStatusCode)
                {
                    PublicationInfo messageInfo = await response.Content.ReadAsAsync<PublicationInfo>();
                    string json = JsonConvert.SerializeObject(messageInfo);
                    Console.WriteLine(json);
                }
            }
        }
    }
}