Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

I have released a beta snapshot version of a Java wrapper for the Stack Overflow API at http://code.google.com/p/stackoverflow-java-sdk/. Please try it and provide your feedback.

Screenshot / Code Snippet

There are two different interfaces to the API. One is the query API which has a Builder like syntax.

    StackExchangeApiQueryFactory queryFactory = StackExchangeApiQueryFactory.newInstance("applicationKey");
    QuestionApiQuery query = queryFactory.newQuestionApiQuery();
    List<Question> questions = query.withSort(Question.SortOrder.HOT).withPaging(new Paging(1, 20)).withTimePeriod(new TimePeriod(new Date(), new Date())).withFetchOptions(EnumSet.of(FilterOption.INCLUDE_BODY, FilterOption.INCLUDE_COMMENTS)).list();

The other is a simple facade which exposes all the methods of the API.

    StackExchangeApiClientFactory factory = StackExchangeApiClientFactory.newInstance("applicationKey");
    StackExchangeApiClient client = factory.createStackOverflowApiClient();
    List<Question> questions = client.getQuestions(Question.SortOrder.HOT, new Paging(1, 20), new TimePeriod(new Date(), new Date()), EnumSet.of(FilterOption.INCLUDE_BODY, FilterOption.INCLUDE_COMMENTS));

The lists returned by both the methods are instances of PagedList which provide methods to aid in pagination of the result.

Note that, by default, the library uses Stack Overflow as the API provider. You can change that to use any other by:

    query.setApiProvider(new SuperUserApiProvider());
    client.setApiProvider(new SuperUserApiProvider());

The method AND class names somewhat map with the names in the API. In case of confusion, look in the examples directory of the distribution for more examples. I will be updating the Javadoc soon.

About

stackoverflow-java-sdk is an open source library hosted at Google Code. I created this library to be used in an internal project. But it's comprehensive enough to be used by anyone looking to integrate with the API of Stack Overflow or partner sites.

License

stackoverflow-java-sdk is open source with an Apache License 2.0.

Download

You can download the library from Google Code at http://code.google.com/p/stackoverflow-java-sdk/.

Platform

It's supported for any platform on which Java is supported which include Google App Engine and Android.

Contact

Any issues can be filed on the Google Code Issue tracking system.

Code

The library is hosted at Google Code as a Mercurial repository. You can create a clone and get the code and make changes to it.

To contribute to the main repository you will have to create an issue with a pull request with details of your changes.

The library has one dependency on Google GSON which can be downloaded from http://code.google.com/p/google-gson/.

share|improve this question
    
Will this work with J2ME development? Just wonderin'... –  Nathan Osman May 25 '10 at 5:46
    
It uses HttpUrlConnection to communicate with the API. HttpUrlConnection is available in J2ME CDC profiles, so theoretically it should work on those platforms, though I have not tried it. So not sure. –  nabeelmukhtar May 25 '10 at 6:58
1  
Might want to change the name... you're not supposed to use 'StackOverflow' in the name. –  Nathan Osman Jul 5 '10 at 19:50
    
You are right. The names were old and have been updated. –  nabeelmukhtar Jul 7 '10 at 8:54
    
@nabeelmukhtar any plans to support api 2.1? –  Binoy Babu Nov 10 '12 at 5:09
add comment

3 Answers 3

Vineet,

Try below one, I have added support for Stack Exchange API V2.x

https://github.com/sanjivsingh/stackoverflow-java-sdk

For more detail, follow docs https://github.com/sanjivsingh/stackoverflow-java-sdk/wiki

share|improve this answer
add comment

This currently does not work with the v2.0 API.

share|improve this answer
add comment

This is a nice implementation, but it doesn't work on Java ME nor Android though. You seem to be experienced Java developer, because you are using the adapter pattern design and some introspection stuff.

The main problem here is that Java ME and Android don't provide the java.beans package which is needed in order to use introspection as you are using it... even worse, the Dalvik VM avoids compiling 'core' libraries so I was not able to adapt the java.beans implementation for Android.

There are other problems, which are easier to solve, like the way you are getting the application constants values (for instance, that won't work on Java ME unless you use microproperties).

I guess someone will have to implement a wrapper for Android that uses the JSON libraries provided by the Android API. Maybe I could give it a try in some days.

I also took a look of the Stack Exchange Java client library; it seems to be simpler, but it uses the Java Jersey API, and I haven't been able to make it run on Android...

share|improve this answer
    
Thanks for pointing this out. I will have to change the BaseJsonAdapter implementation to use reflection etc. for android. Let me try this. Will have to change a lot to support j2me though. –  nabeelmukhtar Jun 15 '10 at 13:04
    
You could better start with Android since it has a richer SDK... the changes won't be dramatic. For j2me I guess it'd be better to create a miniwrapper version. –  Cristian Jun 15 '10 at 13:12
2  
@Christian: If you'd like, you can test out StackWrap4J. I tested it out on the Android emulator, but I don't have a physical device to test it on yet. I'd appreciate any feedback you can give us if you decide to use it. Thanks. –  Bill the Lizard Jun 21 '10 at 3:06
    
@Bill Thanks! I'll give it a try as soon as I can :D –  Cristian Jun 30 '10 at 13:54
    
Try the latest version. It uses Google GSON for json parsing which works on Android as well. –  nabeelmukhtar Jul 5 '10 at 12:52
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .