| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Swarm API Examples

Page history last edited by Brandon Geiger 14 years, 8 months ago

 

<< Back to Swarm API Documentation

 

The Swarm Developer Community is always looking for new examples and code on on how to use the API. If you have some you want to share send them our way. For now, check out these simple, easy-to-implement code samples:

 

 

 

PHP Example

 

cURL (about cURL) in PHP (about PHP):

 

//////////////////////////////////////////////////////////////////////////////

// make the call for a tweets - begin

//////////////////////////////////////////////////////////////////////////////

 

//set api url

$url="http://api.swarmforce.com/v1.0/GetTweetsBySwarm/";

 

//set arguments

$args=array("swarm_id"=>1015,"count"=>10);

 

//set up cURL call

$session = curl_init();

curl_setopt ( $session, CURLOPT_URL, $url );

curl_setopt ( $session, CURLOPT_HTTPHEADER, array('Expect:'));

curl_setopt ( $session, CURLOPT_RETURNTRANSFER, 1 );

curl_setopt ( $session, CURLOPT_POST, 1);

 

//get arguments

if(count($args)>0){

    $params="";

    foreach($args as $key => $value){

        $params.=$key."=".urlencode($value)."&";

    }

    $params=substr($params,0,strlen($params)-1);

    curl_setopt ( $session, CURLOPT_POSTFIELDS, $params);

}

 

//execut call

$result_tmp= curl_exec ( $session );

 

//decode json string

$result= json_decode($result_tmp); 

 

//close cURL

curl_close( $session );

 

//////////////////////////////////////////////////////////////////////////////

// make the call for tweets - end

//////////////////////////////////////////////////////////////////////////////

 

//now output just to view data 

echo $result->name;

 

 

Ruby Example

 

 
require 'net/http'

require 'uri'

require 'rubygems'

require 'json'

 

 

#//////////////////////////////////////////////////////////////////////////////

#// set url to parse

#//////////////////////////////////////////////////////////////////////////////

 

 

uri = URI.parse('http://api.swarmforce.com/v1.0/GetSwarm/')

params = { :swarm_id => 1015 }

 

response = Net::HTTP.post_form(uri, params)
puts JSON.parse(response.body).inspect


 

 

Do you have an example to share in the language of your choice? Please share!

 

<< Back to Swarm API Documentation

 

 

 

Comments (0)

You don't have permission to comment on this page.