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 want to write a program using PhoneGap. How can I use the Stack Exchange API in PhoneGap?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
I dont think "cache: true" is appropriate because its very much possible that the answer might have been edited. –  Bhavik Shah Sep 19 '13 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. –  Brock Adams Oct 25 '13 at 20:13
add comment

You must log in to answer this question.

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