2

I want to write a program using PhoneGap. How can I use the Stack Exchange API in PhoneGap?

1 Answer 1

2

I haven't used PhoneGap yet, but they claim that you develop apps with plain old JS, CSS, and HTML.

If that's true, then use the API just like you would from a web page -- with simple AJAX calls.

Here's a working example (using jQuery):

var userID      = 1416412;
var pageNum     = 1;
var pageSize    = 100;
var siteParam   = 'stackoverflow';
var appKey      = 'Get your own key!';

$.ajax ( {
    type:       'GET',
    url:        'https://api.stackexchange.com/2.1/users/' + userID
                + '/answers?page=' + pageNum
                + '&pagesize=' + pageSize + '&order=desc&sort=votes'
                + '&site=' + siteParam
                + '&filter=!3u0zcO(lpHVEGuskA&key=' + appKey,
    dataType:   'JSON',
    cache:      true,
    success:    function (apiJson) {
                    //-- Provide a closure.
                    console.log (apiJson);
                }
} );


Get a key, it greatly increases your quota and is needed if you want one of the methods that needs authentication.

Reference the API docs and the API “Hello World” code.

2
  • I dont think "cache: true" is appropriate because its very much possible that the answer might have been edited. Sep 19, 2013 at 11:02
  • @BhavikShah, this cache has nothing to do with that and will not miss updates. It's just about not refetching the exact same data unnecessarily. Oct 25, 2013 at 20:13

You must log in to answer this question.

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