我正在尝试使用 Xively4J 从 Xively 获取数据流。我已经下载了snapshot jar from Sonatype repo 。我认为有一个 getDatastreams() 方法,但这个方法很奇怪,因为它不接受参数。如何使用此方法从特定 Xively 源获取我想要的数据流?有人可以给我一个使用这种方法的例子吗?
最佳答案
下面的代码片段列出了您的特定 Feed 的 channel 名称:
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 key 没有任何引号的图书馆。例如:
# The key used for authenticating API calls.
api.key=rtBB60ref6TRi23yQeWMfI0034DRDsYdd4lbJjRZoFLQI00
关于java - 在 Eclipse 中获取 Xively 数据流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19093684/