I am trying to get the datastream from Xively using Xively4J. I have download snapshot jar from Sonatype repo. I figured that there is a getDatastreams()
method, but this method is strange because it doesn't take arguments. How can I use this method to get the datastream that I want from a specific Xively feed? Can someone give me an example to use this method?
Asked
Active
Viewed 332 times
1

errordeveloper
- 6,716
- 6
- 41
- 54

Alvinadi Wijaya
- 45
- 1
- 7
1 Answers
0
Here's a snippet which lists the channels' names of your specific 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
Make sure you have added your API key on the file src/main/res/config.properties of the library without any quotes. e.g.:
# The key used for authenticating API calls.
api.key=rtBB60ref6TRi23yQeWMfI0034DRDsYdd4lbJjRZoFLQI00

foivaras
- 238
- 4
- 11
-
bhantol are you sure you know what xively and xively4j is? 2 of the edits you propose make the post incorrect. 1)the correct path is the one before the edit(main/res/config.properties) 2)every feed has many channels so your correction was not only unnecessary but made the sentence imply that thre is one channel with many names which is nonsense... – foivaras Nov 03 '14 at 09:55