Archive

Posts Tagged ‘api’

Feed Posting API Beta Release

May 8th, 2010 Brad 7 comments

We want to make it is as easy as possible for our publishers to get their content on FeedAgg.com to get exposure and audiences.  To help with that we announced the start of a feed posting API almost a year ago. We have since then rewritten it in a more formal restful API interface.  Below you will find the basics for using it. Feed content policies still apply. Please give us any feedback, good or bad, on how it works for you.

Background

Feed addition requests can be posted to http://www.feedagg.com/add_feed_api.php. You will receive the response as xml containing either a success code(200) or error code(400′s and 500′s).  Successful posts will include the FeedAgg.com url for your feed.

* The API is in a very beta stage and error status codes (ie >200) may change. *

Error codes are 400′s and 500′s. Success codes are 200′s.

A minimum of one tag per feed is required, max 100 50.

Feed submissions via API require a username.

URL Encode your feed urls.

Tags are separated by commas when submitting via API.

Rate limiting still applies. Currently set at 60 submissions per minute.

Updated: 2/10/11

Variables

FeedURL (Required, URL Encoded)

Tags (A minimum of one tag per feed is required, max 100 50.)

UserName (Required)

Example Successful Submission XML Response

<?xml version="1.0" encoding="UTF-8"?>
<response>
     <status_code>200</status_code>
     <status_txt>Your feed, FeedAgg Blog, has been saved.</status_txt>
     <data>
          <title>FeedAgg Blog</title>
          <submitted_url>http://www.feedagg.com/blog/feed/</submitted_url>
          <feedagg_url>http://www.feedagg.com/feed/258970/FeedAgg</feedagg_url>
          <feedagg_id>258970</feedagg_id>
     </data>
</response>

Example PHP(v5.0) Code To Submit VIA API

//---------------------------------------------------------------------------------
// The feedagg.com API address
 $url = 'http://www.feedagg.com/add_feed_api.php';
// Set up and execute the curl process
 $curl_handle = curl_init();
 curl_setopt($curl_handle, CURLOPT_URL, "$url");
 curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
 curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl_handle, CURLOPT_POST, 1);
 curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "FeedURL=".urlencode('http://www.feedagg.com/blog/feed/')."&Tags=tag1,tag2&UserName=<yourusername>");
 $buffer = curl_exec($curl_handle);
 curl_close($curl_handle);

// check for success or failure
 if (empty($buffer))
 {
      echo 'message' . "<br>";
 }
 else
 {
      echo 'success' . "<br>";
 }

//load to xml obj
 $xml = simplexml_load_string($buffer);

//sample results
 echo "code " . $xml->status_code . "<br>";
 echo "message " . $xml->status_txt . "<br>";
 echo "title " . $xml->data->title . "<br>";
 echo "submitted_url " . $xml->data->submitted_url .  "<br>";
 echo "feedagg_url " . $xml->data->feedagg_url . "<br>";
 echo "feedagg_id " . $xml->data->feedagg_id . "<br>";

Example C# Code To Submit VIA API
Courtesy of one of our users.  Thank you!


using System;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Collections.Specialized;

namespace FeedAggExample
{
 public class FeedAgg
 {
 private const string FeedAggApiUrl = "http://www.feedagg.com/add_feed_api.php";

 public static string SubmitFeed(string FeedUrl, string Tags, string Username)
 {
 //set up the return value
 string returnValue = "";

 //Create a name value collection to hold the paramaters to be passed in the post
 NameValueCollection m_values = new NameValueCollection();

 //add all of the specified values
 m_values.Add("FeedURL", FeedUrl);
 m_values.Add("Tags", Tags);
 m_values.Add("UserName", Username);

 //encode the paramaters
 StringBuilder parameters = new StringBuilder();
 for (int i = 0; i < m_values.Count; i++)
 {
 EncodeAndAddItem(ref parameters, m_values.GetKey(i), m_values[i]);
 }

 try
 {
 //set up the request
 HttpWebRequest request = null;
 Uri uri = new Uri(FeedAggApiUrl);
 request = (HttpWebRequest)WebRequest.Create(uri);
 request.Method = "POST";
 request.ContentType = "application/x-www-form-urlencoded";
 request.ContentLength = parameters.ToString().Length;
 using (Stream writeStream = request.GetRequestStream())
 {
 UTF8Encoding encoding = new UTF8Encoding();
 byte[] bytes = encoding.GetBytes(parameters.ToString());
 writeStream.Write(bytes, 0, bytes.Length);
 }

 //Set up the response
 HttpWebResponse response = (HttpWebResponse)request.GetResponse();

 if (response.StatusCode == HttpStatusCode.OK)
 {
 using (Stream responseStream = response.GetResponseStream())
 {
 using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
 {
 returnValue = readStream.ReadToEnd();
 }
 }
 }
 else
 {
 returnValue = String.Format("Error: There was an error processing the request. The exact error was: {0} {1}", response.StatusCode, response.StatusDescription);
 }

 }
 catch (Exception ex)
 {

 returnValue = "Exception occured while processing your request. The exception was:" + ex.Message;
 }

 return returnValue;
 }

 /// <summary>
 /// Encodes an item and ads it to the string.
 /// </summary>
 /// <param name="baseRequest">The previously encoded data.</param>
 /// <param name="dataItem">The data to encode.</param>
 /// <returns>A string containing the old data and the previously encoded data.</returns>
 private static void EncodeAndAddItem(ref StringBuilder baseRequest, string key, string dataItem)
 {
 if (baseRequest == null)
 {
 baseRequest = new StringBuilder();
 }
 if (baseRequest.Length != 0)
 {
 baseRequest.Append("&");
 }
 baseRequest.Append(key);
 baseRequest.Append("=");
 baseRequest.Append(System.Web.HttpUtility.UrlEncode(dataItem));
 }

 }
}
Categories: New Features, News Tags: , , ,

FeedAgg API – Adding Feeds

June 7th, 2009 Brad 1 comment

5/8/10 Update – A formal api has been released here

I haven’t made a formal feed posting API but many people have reverse engineered the Add Feed page to essentially create one. One thing that was missing doing it this way however was that you would not be able to assign ownership to your feed. I’ve made some changes to the Add Feed page to allow ownership and thought that while I was at it I would make a more formal post on how to add feeds via REST.

While this isn’t a formal API, mainly because it doesn’t return anything, it will at least serve the basic purpose at this point in time.

Basics

Send a POST request to: http://www.feedagg.com/add_feed.php

Variables

FeedURL (Required)

Tags (At least one required)

UserName (Optional)

Example

http://www.feedagg.com/add_feed.php?FeedURL=http://example.com/feed.xml&Tags=tag-1 tag2 tag3&UserName=example

Notes

At this time there isn’t a response from the server but that will be coming in the future.

Given the nature of this there will be limited support of this feature for the time being.

Categories: New Features Tags: