This document is divided into three sections:
Gnip provides a set of services for accessing, filtering and integrating data from web APIs and feeds. To get started using the Gnip Platform first create an account. You can create one at the Gnip Developer site in seconds. The Gnip Platform API is based on the REST approach (see Wikipedia for a definition of REST if you need one), and we provide convenience libraries for several popular languages (PHP, Java, .NET, Python, Perl and Ruby), so you can be up and running in the language or your choice in no time. The Gnip API version of this document is version 2.1. At Gnip we use the hostname as the way to version the API, this means to access the 2.1 version of the Gnip API, you will need to use the host: https://api-v21.gnip.com. Also, if you connect to the default host URL for the Gnip platform at https://api.gnip.com it will redirect to the most recent version available.
There are two main data integration use cases supported by the Gnip Platform: Publishers & Data Consumers. Publishers represent the sources of data available through the Gnip Platform from different web APIs and feeds across the Internet, and Data Consumers, represent the developers and companies that use the Gnip Platform to access, filter and integrate social and business data into their applications. Developers have the choice of using the Gnip Developer Site or the Gnip Platform APIs to integrate data. In additioin, Gnip provides online support at the Gnip Developer Forums.
The Gnip Platform APIs provides access to normalized event data. An activity contains all event meta-data and the data payload. The data payload represents the full raw data, from a data source (e.g, such Digg, Delicious, Twitter, Sixapart, etc). A notification is the subset of an activity and contains all the event meta-data, just no data payload. By providing these two options developers obtain the flexibility to request the type of data needed for their application and use case. Also, the data payloads included in an activity provide the raw, original, untouched (though encoded) event information from the data source that Gnip maps to the normalized Gnip XML schema. Gnip maps as much of the relevant raw data to the Gnip XML schema so that Data Consumers can satisfy most of their use cases without the need to proces the raw activity data payload. In order to protect the integrity of the Gnip XML, the raw payload is gzip'd and base64 encoded within the xml document and is called the <raw> element. Data Consumers are responsible for decoding and un-gzip'ing the raw element if they need direct access to the original data and this can be easily done with the Gnip Convenience Libraries.
An error represented in XML looks like this:
<error>"foo_bar" is not a valid publisher name. Only letter, number, '.', '+' and '-' characters are allowed in publisher names.</error>
| URL | Method | Details |
https://api-v21.gnip.com/gnip/publishers.xml |
GET | Returns a list of Gnip endorsed publishers |
https://api-v21.gnip.com/gnip/publishers.xml
|
POST | Creates a new publisher, defined in Publisher XML Schema sent |
https://api-v21.gnip.com/gnip/PublisherName
|
Delete | Only Gnip can delete a Gnip endorsed publisher |
| URL | Method | Details |
|
GET | Returns publisher's activity based for PUBLISHER-NAME, for most publishers will return HTTP error 401, unauthorized. If your unauthorized use a filter. |
https://api-v21.gnip.com/gnip/PUBLISHER-NAME/notification.xml
|
GET | Returns publisher's activity based for PUBLISHER-NAME, for some publishers will return HTTP error 401, unauthorized. If your unauthorized use a filter. |
|
POST | Only Gnip can post activity for a Gnip endorsed publisher |
https://api-v21.gnip.com/gnip/publishers.xml
|
Delete |
Only Gnip can delete a Gnip endorsed publisher |
| URL | Method | Details |
|
GET | Returns publisher's current notification activity for Gnip endorsed PUBLISHER-NAME, some publishers this will return a HTTP error 401, unauthorized |
https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/notification/BUCKET-ID.xml
|
GET | Returns publisher's notification activity from BucketID for PUBLISHER-NAME, for some publishers this will return a HTTP error 401, unauthorized. |
https://api-v21.gnip.com/gnip/publishers/PUBLISHER- NAME/activity/current.xml
|
GET | Returns publisher's current notification activity for Gnip endorsed PUBLISHER-NAME, most publishers this will return a HTTP error 401, unauthorized |
|
GET | Returns publisher's full-data activity from BucketID for PUBLISHER-NAME, for nearly all publishers this will return a HTTP error 401, unauthorized. |
| URL | Method | Details |
|
GET | Returns publisher's current notification activity for Gnip PUBLISHER-NAME |
https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME/notification/BUCKET-ID.xml
|
GET | Returns publisher's notification activity from BucketID for Gnip PUBLISHER-NAME |
https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME/activity/current.xml
|
GET | Returns publisher's full-data activity for Gnip PUBLISHER-NAME |
https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME/activity/BUCKET-ID.xml
|
GET | Returns publisher's full-data activity from BucketID for PUBLISHER-NAME |
| URL | Method | Details |
|
GET | Lists all the filters and the rules owned by you on a Gnip endorsed feed. |
https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters.xml
|
POST | Accepts a Filter XML document and creates a new filter based on that information |
| https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME.xml | GET | Returns the FILTER-NAME and the XML definition of the filter |
| https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME.xml | POST | Will create/over-ride a filter with Filter-NAME with a Filter XML instance posted |
| https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME.xml | PUT | Accepts a Filter XML document and updates the specified Filter to match the data provided |
| https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME.xml | DELETE | Deletes a based on FILTER-NAME on a publisher PUBLISHER-NAME on a Gnip endorsed data feed. |
https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME/activity/BUCKET-ID.xml
|
GET | Returns publisher's notification activity from BucketID on filter FILTER-NAME that is on publisher PUBLISHER-NAME |
https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME/notification/BUCKET-ID.xml
|
GET | Returns publisher's full data activity from BucketID on filter FILTER-NAME that is on publisher PUBLISHER-NAME |
| URL | Method | Details |
|
GET |
Accepts a rule description to search for in the Filter using a query string of the form ?type=actor&value=joe |
| https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME/rules.xml | POST | Accepts either a <rule/> or <rules/> document and adds the rules to the filter named FILTER-NAME. Use the <rules/> document to batch add rules to a Filter. |
| https://api-v21.gnip.com/gnip/publishers/PUBLISHER-NAME/filters/FILTER-NAME/rules | DELETE | Accepts a <rules/> document that contains a batch of <rule/> objects to delete from the user's filter named FILTER-NAME. This should be used to batch delete rules from a Filter. Also accepts a query string to specify a single rule to delete in the form ?type=actor&value=joe. |
| URL | Method | Details |
https://api-v21.gnip.com/my/publishers.xml |
GET | Returns a list of your publishers |
https://api-v21.gnip.com/my/publishers.xml
|
POST | Creates a new publisher, defined in Publisher XML Schema sent |
https://api-v21.gnip.com/my/PublisherName
|
DELETE |
Deletes a publisher with PublisherName |
| URL | Method | Details |
|
GET | Returns publisher's activity based for PUBLISHER-NAME |
https://api-v21.gnip.com/my/PUBLISHER-NAME/notification.xml
|
GET | Returns notification methods based for PUBLISHER-NAME |
|
POST | Publishes an activity based on the activity schema. You only need to publish to activity.xml, Gnip will create another type of activity called notifications from this. (That is there will be full-data activity and notifications (activity) without payload |
https://api-v21.gnip.com/my/publishers.xml
|
DELETE | Deletes a publisher, defined in the Publisher XML Schema |
| URL | Method | Details |
|
GET | Returns publisher's current notification activity for PUBLISHER-NAME |
https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/notification/BUCKET-ID.xml
|
GET | Returns publisher's notification activity from BucketID for PUBLISHER-NAME |
https://api-v21.gnip.com/my/publishers/PUBLISHER- NAME/activity/current.xml
|
GET | Returns publisher's current full data activity for PUBLISHER-NAME |
|
GET | Returns publisher's full data activity from BucketID for PUBLISHER-NAME |
| URL | Method | Details |
|
GET | Returns publisher's current notification activity for PUBLISHER-NAME |
https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME/notification/BUCKET-ID.xml
|
GET | Returns publisher's notification activity from BucketID for PUBLISHER-NAME |
https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME/activity/current.xml
|
GET | Returns publisher's full-data activity for PUBLISHER-NAME |
https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME/activity/BUCKET-ID.xml
|
GET | Returns publisher's full-data activity from BucketID for PUBLISHER-NAME |
| URL | Method | Details |
|
GET | Lists all the filters and the rules owned by you. |
https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters.xml
|
POST | Accepts a Filter XML document and creates a new filter based on that information |
| https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME.xml | GET | Returns the FILTER-NAME and the XML definition of the filter |
| https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME.xml | POST | Will create/over-ride a filter with Filter-NAME with a Filter XML instance posted |
| https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME.xml | PUT | Accepts a Filter XML document and updates the specified Filter to match the data provided |
| https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME.xml | DELETE | Deletes a filter based on FILTER-NAME on a publisher PUBLISHER-NAME you own. |
https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME/activity/BUCKET-ID.xml
|
GET | Returns publisher's notification activity from BucketID on filter FILTER-NAME that is on publisher PUBLISHER-NAME |
https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME/notification/BUCKET-ID.xml
|
GET | Returns publisher's full data activity from BucketID on filter FILTER-NAME that is on publisher PUBLISHER-NAME |
| URL | Method | Details |
|
GET | Accepts a rule description to search for in the Filter using a query string of the form ?type=actor&value=joe |
| https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME/rules.xml | POST | Accepts either a <rule/> or <rules/> document and adds the rules to the filter named FILTER-NAME. Use the <rules/> document to batch add rules to a Filter. |
| https://api-v21.gnip.com/my/publishers/PUBLISHER-NAME/filters/FILTER-NAME/rules | DELETE | Accepts a <rules/> document that contains a batch of <rule/> objects to delete from the user's filter named FILTER-NAME. This should be used to batch delete rules from a Filter. Also accepts a query string to specify a single rule to delete in the form ?type=actor&value=joe. |
<?xml version="1.0" encoding="utf-8"?>
<activities publisher="gnip-sample">
<activity>
<at>2009-02-02T17:16:01.000Z</at>
<action>post</action>
<activityID>0.516958128858</activityID>
<URL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.xml</URL>
<source>Vignette-Web-Publisher</source>
<place> <elev>5,368 meters</point> <floor>2nd</floor> <point>38.2638886 -106.126131</point>
<featurename>Chloride Mine</featurename> <featuretypetag>Colorado</featuretypetag > <relationshiptag>middle</relationshiptag> </place>
<actor uid="12339948@4994" metaURL="http://gnipherald.com/profiles/jvaleski">jvaleski</actor>
<destinationURL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.html</destinationURL>
<tag metaURL="http://gnipherald/about/tag/armor">armor</tag>
<tag metaURL="http://gnipherald/about/tag/staff">staff</tag>
<tag metaURL="http://gnipherald/about/tag/injury">injury</tag>
<to metaURL="http://gnipherald.com/profiles/barinek">barinek</to>
<regardingURL metaURL="http://apnewswire.com/jousting">http://apnewswire.com/jousting/accident.html</regardingURL>
<payload>
<title>Jousting Event Went Awry</title>
<body> Two drunken guys, two jousting sticks, blindfolds and running full bore down a hallway at each other, lead to a night in hospital for two university students. One with chest injury the other unharmed. REST of BODY </body>
<mediaURL mimeType="jpg" height="600" width="400" >http://images.gnipherald.com/jousting-thumbnail.jpg</mediaURL> <raw>base64 encoded gzip compressed binary</raw>
</payload>
</activity>
</activities>Each activity must have an <at> and an <action>, <at> must be in UTC time. Every other element / attribute is optional. Note: the more information you provide in the schema the more rich the information, the greater syndication of your data. Our convenience libraries for most popular languages will put the time in UTC format, gzip the request and the response and base64 with gzip the <raw> part of the message. The convenience libraries can be find them here.Schema Explanation Details:
<at>is the time the activity was done<action> what activity was performed<activityID> is any value a publisher wishes to use to reference this information - be it a GUID, url, string, etc up to the discretion of the publisher <URL> contains the machine-readable metadata for the activity<source> is the mechanism by which the event was published for example, web, mobile, txt, partner's name, etc
<actor> is the person who performed the activity
<posts> is the number of updates made by the user
<followers> is the number of people following the user
<friends> is the number of people the user has friended
<fullname> is fullname or screen name for the user
<username> is username of the user on the service
<metaURL> is the user profile link on the service
<uid> is the user numeric ID on the service
<destinationURL> is the link to the actual activity, for example links to the actual post of a comment, tweet, video upload, etc If you use more than one destinationURL make sure the first destinationURL points to the human readable story of the action. <metaURL> is the link to the page about the result of the activity
<to> is the person the action is in reply to <metaURL> is the link to the user profile of the user on the service
<uid> is the user numeric ID on the service
<regardingURL> is the link to what was replied to <metaURL> is the link to the thread's root
<tag> a tag <metaURL> is a link to the publisher's page on this tag
<payload> This is where the title, body, and the raw base64 gzip message (can be in a different format than gnip's) with one ore more mediaURLs
<title> the title of the activity <body> the body of the activity, or description if there's no body <raw> is the base64 gziped message, the unmodified publisher data/metadata for an activity. Raw can be empty
<mediaURL> (can have more than one mediaURL) <mimeType> is the mime type of the media, eg, image/jpeg <type> is the type of media, types today are: avatar, video, flash <height> is the height of the enclosure <width> is the width of the enclosure <duration> is the duration of the enclosure, it can be any string format today such as 2m and 3s, we may put in some formats in the future
<place> is based on the GeoRSS standard. <point> is the location containing a single latitude-longitude pair, separated by whitespace <elev> is the meant to contain the "common" GPS elevation readings, i.e. height in meters <floor> is meant to contain the floor number of a building <featurename> is meant to refer to the location or feature <relationshipTag> is a way of relating Web content to the Earth features, see GeoRSS for more details. <featureTypeTag> is meant to represent a real feature of the Earth's surface
XSD of the activity SchemaFull Gnip XML schema can be found here.
...
<xs:element name="activity">
<xs:complexType>
<xs:sequence>
<xs:element name="at" type="xs:dateTime" minOccurs="1" maxOccurs="1" />
<xs:element name="action" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="activityID" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="URL" type="xs:anyURI" minOccurs="0" maxOccurs="1" />
<xs:element name="source" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="keyword" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="place" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="point" type="pointType" minOccurs="0" maxOccurs="1" />
<xs:element name="elev" type="xs:double" minOccurs="0" maxOccurs="1" />
<xs:element name="floor" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="featuretypetag" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="featurename" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="relationshiptag" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="actor" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="metaURL" use="optional" type="xs:anyURI" />
<xs:attribute name="uid" use="optional" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="destinationURL" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:attribute name="metaURL" use="optional" type="xs:anyURI" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="tag" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="metaURL" use="optional" type="xs:anyURI" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="to" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="metaURL" use="optional" type="xs:anyURI" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="regardingURL" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:attribute name="metaURL" use="optional" type="xs:anyURI" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="payload" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="body" type="xs:normalizedString" minOccurs="0" maxOccurs="1" />
<xs:element name="mediaURL" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:attribute name="height" use="optional" type="xs:string" />
<xs:attribute name="width" use="optional" type="xs:string" />
<xs:attribute name="duration" use="optional" type="xs:string" />
<xs:attribute name="mimeType" use="optional" type="xs:string" />
<xs:attribute name="type" use="optional" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="raw" type="xs:base64Binary" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
...
</xs:schema>
Activity streams are collections of activities which may be retrieved and, in some situations, to which activities may be published. Publishers POST new activities to activity streams; they are the start of data flow through the system. Subscribers can retrieve activity data via activity buckets (see the Activity Buckets section below). There is no synchronizing of time between the Gnip server and your local server is needed on this request as it lists the buckets to traverse to retrieve information.
Activity streams are segmented into buckets based on time. Each bucket contains all the activities for the stream that are reported during the bucket’s duration. Each bucket has an ID that is the time stamp, in UTC, of the first minute bucket. The bucket ID format is %Y%m%d%H%M%S (e.g. the strftime conversion spec). For example, bucket with ID 200806090913 would contain all activity reported during between 9:13 am and 9:14 UTC am, inclusive, on June 9, 2008. Activity buckets are only valid for the last 60 minutes. The "current.xml" bucket holds the "current" activities up to one minute. Please note that the current bucket is not static, so retrieving data from this bucket may not be reliable for your application. The same goes for the 0-1 minute old bucket. Until the full minute is up, the bucket will continue to accrue data.
Request Accept-Encoding: gzip (optional but recommended, our convenience libraries support this)Request Content-Encoding: gzip (optional but recommended, our convenience libraries support this)Activity definitions are represented as XML documents similar to this.
Descriptions of element and attribute schema details can be found here .
Activity XML document conform to the following schema.
A Filter consists of rules that are used to match activities flowing through a Publisher's activity stream. Filters may be created, edited, and deleted at will by their owner. Filter rules are OR'd together; there is no AND support. Since your filter is created on a per publisher basis, the URI will reflect the namespace of that publisher ("my" or "gnip"). Filters can be created and edited through the Developer website, a walkthru is found in the "Configuring filters through the Gnip Developer Site".
The following rule-types are supported:
For any rule value, be it actor, keyword or tag, we will URL encode all URLs to the respective publishers.
URL encoding
GNIP will URL encode all string values in keywords, actors, source only using the Gnip Web UI. Note: When using the XML API it needs to be well formed XML, so properly encode the html entities.
If a Filter specifies a postURL, new activities that meet the collection criteria will be posted to the specified URL. POSTed activities include full data by default.
Request Accept-Encoding: gzip (optional but recommended if a lot of filters, our convenience libraries support this)Request Content-Encoding: gzip (optional but recommended, our convenience libraries support this)
Response Content-Type: application/xmlRequest Accept-Encoding: gzip (optional but recommended, our convenience libraries support this)Request Content-Encoding: gzip (optional but recommended, our convenience libraries support this)
Response Content-Type: application/xmlFilter definitions are represented as XML documents similar to this.
Filter XML document conform to the following schema. Full Gnip XML schema can be found here.
Each publisher supports a different set of one or more rules. To review the list of supported rule types, you can view the schema document. Currently, the types are:
actor
tag
to
regarding
source
To find out if a publisher supports the rule types, you can look at the list of Publishers, the action types they support, and example XML output.
Request Accept-Encoding: gzip (optional but recommended, our convenience libraries support this) Request Content-Encoding: gzip (optional but recommended, our convenience libraries support this)
Response Content-Type: application/xml Request Content-Encoding: gzip (optional but recommended, our convenience libraries support this)
Response Content-Type: application/xmlFilters can be subscribed to in such a way that any time activities are published that match the Filter criteria, those activities are pushed, via a HTTP POST, to a configurable URL. The URL to which activities will be pushed is specified by the postURL of the Filter XML. Any activities added to a Filter which has a <postURL/>, will automatically be POSTed to that URL. The body of these POSTs will be an Activities XML document (described above in the Activity Buckets section). Responses to these requests are ignored. PostURLs must be valid. Gnip does not HTTP Post gzip encoded today, we may change this in the future.
POST:
Pushes new activities, as an Activities XML document, to the subcriber to this collection.
Request Content-Type: application/xml
A set of activities are represented in XML documents that look like this. Full Gnip XML schema can be found here.
<?xml version="1.0" encoding="utf-8"?>10
0<activities publisher="gnip-sample">
<activity>
<at>2009-02-02T17:16:01.000Z</at>
<action>post</action>
<activityID>0.516958128858</activityID>
<URL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.xml</URL>
<source>Vignette-Web-Publisher</source>
<place>
<point>38.2638886 -106.126131</point>
<featurename>Chloride Mine</featurename>
</place>
<actor uid="12339948@4994" metaURL="http://gnipherald.com/profiles/jvaleski">jvaleski</actor>
<destinationURL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.html</destinationURL>
<tag metaURL="http://gnipherald/about/tag/armor">armor</tag>
<tag metaURL="http://gnipherald/about/tag/staff">staff</tag>
<tag metaURL="http://gnipherald/about/tag/injury">injury</tag>
<to metaURL="http://gnipherald.com/profiles/barinek">barinek</to>
<regardingURL metaURL="http://apnewswire.com/jousting">http://apnewswire.com/jousting/accident.html</regardingURL>
<payload>
<title>Jousting Event Went Awry</title>
<body> Two drunken guys, two jousting sticks, blindfolds and running full bore down a hallway at each other, lead to a night in hospital for two university students. One with chest injury the other unharmed. REST of BODY </body>
<mediaURL>http://images.gnipherald.com/jousting-thumbnail.jpg</mediaURL>
<raw>base64 encoded gzip compressed binary</raw>
</payload>
</activity>
</activities>
To publish an activity:
In three steps:Step One: you need to create a publisher through the API or create a publisher through the Gnip Web UI.
(click on "create one!")
Step TwoDefine which tags you support so that data consumers can set up filters on your data.
Step ThreeUsing the API http POST an activity in Gnip schema format to the below url:
Note: A publisher only needs to publish activity.xml, Gnip will create another type of activity called notifications from this.
POST:https://api-v21.gnip.com/my/PUBLISHER-NAME/activity.xml
Request Content-type: application/xmlRequest Accept-Encoding: gzip (optional but highly recommended for activity buckets over 100k, our convenience libraries support this)Request Content-Encoding: gzip (optional but highly recommended for activity buckets over 100k, our convenience libraries support this)
Response Content-Type: application/xml
Response Content-Encoding: gzip (if gzip is set on request)
https://api-v21.gnip.com/my[gnip]/publishers.xml
Setting scope to 'my' - returns your publisherPublisher definitions are represented as XML documents similar to this. As a Publisher you can define which rules you support. Rule types today are: actor, tag, to, regarding and source. Below is an example of XML that has to, actor and regarding supported.
<?xml version="1.0" encoding="utf-8"?>
<publisher name="mytestpublisher">
<supportedRuleTypes>
<type>to</type>
<type>actor</type>
<type>regarding</type>
</supportedRuleTypes>
</publisher>
Publisher XML document conform to the following schema. Full Gnip XML schema can be found here.
<activities publisher="gnip-sample">
<activity>
<at>2009-02-02T17:05:01.000Z</at>
<action>post</action>
<activityID>0.33783490478</activityID>
<URL>http://gnipherald.com/stories/0.33783490478/jousting-gone-bad.xml</URL>
<source>Vignette-Web-Publisher</source>
<place>
<point>38.2638886 -106.126131</point>
<featurename>Chloride Mine</featurename>
</place>
<actor uid="12339948@4994" metaURL="http://gnipherald.com/profiles/jvaleski">jvaleski</actor>
<destinationURL>http://gnipherald.com/stories/0.33783490478/jousting-gone-bad.html</destinationURL>
<tag metaURL="http://gnipherald/about/tag/armor">armor</tag>
<tag metaURL="http://gnipherald/about/tag/staff">staff</tag>
<tag metaURL="http://gnipherald/about/tag/injury">injury</tag>
<to metaURL="http://gnipherald.com/profiles/barinek">barinek</to>
<regardingURL metaURL="http://apnewswire.com/jousting">http://apnewswire.com/jousting/accident.html</regardingURL>
</activity>
</activities>
Sample of a Gnip Activity XML with full data enabled (.../activity/...)This requires having a prior knowledge of the Publisher ID, a Publisher ID is usually just a commonly known name for the Publisher such as Publisher ID for twitter is "twitter". (A current list of Publisher IDs can be found at https://api.gnip.com/publishers.html. In order to retrieve recent activities for a Publisher (e.g. "gnip-sample"), construct a URL for the Publisher of interest and perform a HTTP GET to retrieve the application/xml representation of that activity stream; for details go here. You can only access activities without full data, e.g. "notifications," for a Publisher's Public Timeline. If you want full data, you need to create a Filter and access it that way; for an example, go here. Publisher data is namespaced, that is, the list of publishers listed on the Gnip API site are scoped to "gnip". When you create a publisher, they will be scoped to "my".
If you are interested in a specific span of time in the past, relative to now, you will need to determine what the difference is between you local clock and Gnip’s clock, to minimize clock drift as a variable in making requests for activities; for details go here.
===>
HEAD /
<---
200 OK
Date: Mon, June 9 2008, 9:08:43
The returned Date header field can be used to figure the difference between Gnip's clock and the local one. Once that is known, the activity bucket ID for the time of interest can be calculated. Once the activity bucket ID is known its URL can be constructed using the same format as above, replacing "current" with an activity bucket ID (e.g. 200806090910), and the data can be retrieved. See the below section called "Activity Buckets". The activity bucket ID is represented in UTC time. Please note that the two buckets, current and 0-1 minutes old contain a variable amount of data, that is, data will continue to be added to the buckets until a full minute has passed. Buckets that are from 1-2 minutes and older contain a data that is fixed.
===>
GET /gnip/publishers/gnip-sample/notification/200806090910.xml
Accept: application/xml
<---
200 OK
Content-Type: application/xml<activities publisher="gnip-sample">
<activity>
<at>2009-02-02T17:05:01.000Z</at>
<action>post</action>
<activityID>0.33783490478</activityID>
<URL>http://gnipherald.com/stories/0.33783490478/jousting-gone-bad.xml</URL>
<source>Vignette-Web-Publisher</source>
<place>
<point>38.2638886 -106.126131</point>
<featurename>Chloride Mine</featurename>
</place>
<actor uid="12339948@4994" metaURL="http://gnipherald.com/profiles/jvaleski">jvaleski</actor>
<destinationURL>http://gnipherald.com/stories/0.33783490478/jousting-gone-bad.html</destinationURL>
<tag metaURL="http://gnipherald/about/tag/armor">armor</tag>
<tag metaURL="http://gnipherald/about/tag/staff">staff</tag>
<tag metaURL="http://gnipherald/about/tag/injury">injury</tag>
<to metaURL="http://gnipherald.com/profiles/barinek">barinek</to>
<regardingURL metaURL="http://apnewswire.com/jousting">http://apnewswire.com/jousting/accident.html</regardingURL>
</activity>
</activities>
Create a Filter and retrieve its Activity
To create a Filter you need one, or more, "rules." Each Publisher has a set of supported rule types which constrain the types of rules that can be specified for a Filter in a Publisher. For example, if a Publisher supports the rule types "Actor" and "To", a Filter can contain rules of using those types but cannot contain rules of type "RegardingURL", "Tag", and "Source". If a Filter is created with a rule type that a Publisher does not support, the server will return a response containing of an error message and error status code. Here is a list of Publishers. In order to find out what rule types a publisher supports you can look here.
Send an HTTP POST request to create a Filter. For details go here.
===>
POST /gnip/publishers/gnip-sample/filters.xml
Accept: application/xml
Content-Type: application/xml
<filter name="examplefilter" fullData="true">
<rule type="actor">jvaleski</rule>
<rule type="actor">ajackson</rule>
</filter>
<---
200 OK
Content-Type: application/xml
<result>Success</result>
Once the Filter is created, accessing full-data activity associated with it is similar to accessing Publishers' notifications. Note that since fullData was specified as true in this example, the result will include the activity payload, and you'll access it via the ".../activity/..." URI. Trying to access the ".../notification/..." URI would generate a "Not Authorized" error.
===>
GET /gnip/publishers/gnip-sample/filters/examplefilter/activity/current.xml
Accept: application/xml
<---
200 OK
Content-Type: application/xml
<activities publisher="gnip-sample">
<activity>
<at>2009-02-02T17:16:01.000Z</at>
<action>post</action>
<activityID>0.516958128858</activityID>
<URL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.xml</URL>
<source>Vignette-Web-Publisher</source>
<place>
<point>38.2638886 -106.126131</point>
<featurename>Chloride Mine</featurename>
</place>
<actor uid="12339948@4994" metaURL="http://gnipherald.com/profiles/jvaleski">jvaleski</actor>
<destinationURL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.html</destinationURL>
<tag metaURL="http://gnipherald/about/tag/armor">armor</tag>
<tag metaURL="http://gnipherald/about/tag/staff">staff</tag>
<tag metaURL="http://gnipherald/about/tag/injury">injury</tag>
<to metaURL="http://gnipherald.com/profiles/barinek">barinek</to>
<regardingURL metaURL="http://apnewswire.com/jousting">http://apnewswire.com/jousting/accident.html</regardingURL>
<payload>
<title>Jousting Event Went Awry</title>
<body>Two drunken guys, two jousting sticks, blindfolds and running full bore down a hallway at each other, lead to a night in hospital for two university students. One with chest injury the other unharmed. REST of BODY</body>
<mediaURL>http://images.gnipherald.com/jousting-thumbnail.jpg</mediaURL>
<raw>base64 encoded gzip compressed binary</raw>
</payload>
</activity>
</activities>
Create a Filter as in the previous example and in addition specify a postURL to which activities should be HTTP POSTed. Gnip validates the URL by making a HEAD request to it, so ensure that the postURL responds successfully to an HTTP HEAD request. For more information go to the detailed filters section.
===>
POST /gnip/publishers/gnip-sample/filters.xml
Accept: application/xml
Content-Type: application/xml
Accept-Encoding: gzip (optional but recommended, our convenience libraries support this)Content-Encoding: gzip (optional but recommended, our convenience libraries support this)
<filter name="examplefilter" fullData="true">
<postURL>http://mysite.example/inbound-activity-handler.cgi</postURL>
<rule type="actor">jvaleski</rule>
<rule type="actor">ajackson</rule>
</filter>
<---
200 OK
Content-Type: application/xml
<result>Success</result>
Once the Filter is created, any activity that matches rules in the filter will be POSTed to the specified URL; see below for an example HTTP exchange that occurs when sending activities to a postURL. Gnip activity POSTing is currently fire-and-forget and does not interpret HTTP response codes from the POST.
===>
POST http://mysite.example/inbound-activity-handler.cgi
Content-Type: application/xml
Accept-Encoding: gzip (optional but recommended, our convenience libraries support this)Content-Encoding: gzip (optional but recommended, our convenience libraries support this)<?xml version="1.0" encoding="utf-8"?><---
<activities publisher="gnip-sample">
<activity>
<at>2009-02-02T17:16:01.000Z</at>
<action>post</action>
<activityID>0.516958128858</activityID>
<URL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.xml</URL>
<source>Vignette-Web-Publisher</source>
<place>
<point>38.2638886 -106.126131</point>
<featurename>Chloride Mine</featurename>
</place>
<actor uid="12339948@4994" metaURL="http://gnipherald.com/profiles/jvaleski">jvaleski</actor>
<destinationURL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.html</destinationURL>
<tag metaURL="http://gnipherald/about/tag/armor">armor</tag>
<tag metaURL="http://gnipherald/about/tag/staff">staff</tag>
<tag metaURL="http://gnipherald/about/tag/injury">injury</tag>
<to metaURL="http://gnipherald.com/profiles/barinek">barinek</to>
<regardingURL metaURL="http://apnewswire.com/jousting">http://apnewswire.com/jousting/accident.html</regardingURL>
<payload>
<title>Jousting Event Went Awry</title>
<body>Two drunken guys, two jousting sticks, blindfolds and running full bore down a hallway at each other, lead to a night in hospital for two university students. One with chest injury the other unharmed. REST of BODY</body>
<mediaURL>http://images.gnipherald.com/jousting-thumbnail.jpg</mediaURL>
<raw>base64 encoded gzip compressed binary</raw>
</payload>
</activity>
</activities>
200 OK
If you are a Publisher interested in publishing Activities to an Activity Stream, POST application/xml to a Publisher created by you in the following example. For details go here. Required fields are:
<at>
<action>
If a payload is added you must also include (it can be empty):
<raw>
The supported Gnip rule types are:
actor
tag
to
regarding
source
If you support one or more of the above rule types, the field for that type is required.
===>
POST /my/publishers/PUBLISHER-NAME/activity.xml
Accept: application/xml
Content-Type: application/xml
Accept-Encoding: gzip (optional but recommended, our convenience libraries support this) Content-Encoding: gzip (optional but recommended, our convenience libraries support this)
<activities publisher="gnip-sample">
<activity>
<at>2009-02-02T17:16:01.000Z</at>
<action>post</action>
<activityID>0.516958128858</activityID>
<URL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.xml</URL>
<source>Vignette-Web-Publisher</source>
<place>
<point>38.2638886 -106.126131</point>
<featurename>Chloride Mine</featurename>
</place>
<actor uid="12339948@4994" metaURL="http://gnipherald.com/profiles/jvaleski">jvaleski</actor>
<destinationURL>http://gnipherald.com/stories/0.516958128858/jousting-gone-bad.html</destinationURL>
<tag metaURL="http://gnipherald/about/tag/armor">armor</tag>
<tag metaURL="http://gnipherald/about/tag/staff">staff</tag>
<tag metaURL="http://gnipherald/about/tag/injury">injury</tag>
<to metaURL="http://gnipherald.com/profiles/barinek">barinek</to>
<regardingURL metaURL="http://apnewswire.com/jousting">http://apnewswire.com/jousting/accident.html</regardingURL>
<payload>
<title>Jousting Event Went Awry</title>
<body> Two drunken guys, two jousting sticks, blindfolds and running full bore down a hallway at each other, lead to a night in hospital for two university students. One with chest injury the other unharmed. REST of BODY </body>
<mediaURL>http://images.gnipherald.com/jousting-thumbnail.jpg</mediaURL>
<raw>base64 encoded gzip compressed binary</raw>
</payload>
</activity>
</activities>
<---
200 OK
Content-Type: application/xml
<result>Success</result>
Set gnipusername=yourgnipaccount@company.com
Set gnippassword=yourpassword
Set host=https://api-v21.gnip.com
For Gnip publishers that are query based it is possible to submit advanced search parameters. if the rule includes additional parameters for language or geo-code then the rule must be formed properly as a query string. This is a BETA feature at this time and is not generally supported.
For example. When using the Twitter-Search publisher to filter on a keyword for the band "Devo" with only English results returned:
http://search.twitter.com/search.atom?q=devo&lang=en
Revision History