在Eclipse中获取Xively数据流

时间:2013-09-30 11:59:17

标签: java eclipse xively

我正在尝试使用Xively4J从Xively获取数据流。我已下载snapshot jar from Sonatype repo。我认为有一个getDatastreams()方法,但这种方法很奇怪,因为它不带参数。如何使用此方法从特定的Xively Feed获取我想要的数据流?有人能给我一个例子来使用这种方法吗?

1 个答案:

答案 0 :(得分:0)

这是一个列出频道的片段'您的特定Feed的名称:

import java.util.Collection;
import java.util.Iterator;

import com.xively.client.XivelyService;
import com.xively.client.model.Datastream;
import com.xively.client.model.Feed;


public class MainClass {

    public static void main(String[] args) {
        Feed feed = XivelyService.instance().feed().get(6630948);  //your feedID as argument

        System.out.println("channels of feed "+feed.getId()+ ":");

        Collection<Datastream> datastreams = feed.getDatastreams();
        Iterator<Datastream> datastreamsIterator=datastreams.iterator();

        while(datastreamsIterator.hasNext()){           
            Datastream currentDatastream=datastreamsIterator.next();    
            System.out.println(currentDatastream.getId());
        }


    }//end main

}//end class

确保已在文件src / main / res / config.properties上添加了API密钥  没有任何报价的图书馆。 e.g:

# The key used for authenticating API calls.
api.key=rtBB60ref6TRi23yQeWMfI0034DRDsYdd4lbJjRZoFLQI00