1

I am developing an Android App that is able to register users on a WordPress website and update their user_meta_vars by sending http requests "GET Method" using the JSON API Auth and JSON API User plugins installed on WordPress.

The problem is that to register a user I have to:

1- Make a request to get the nonce id: "DomainName/api/get_nonce/?controller=user&method=register" this will return a json with nonce id.

2- Another request to register a user: "DomainName/api/user/register/?username=john&email=john@domain.com&nonce=TheIdFromPreviousRequest&display_name=John".

Till now a user is registered.

Now I want to update his user_meta_vars

3- A request for updating user meta using the cookie from registration http request: "DomainName/api/user/update_user_meta_vars/?cookie=COOKIE-HERE&website=user-website.com&city=Chicago&country=USA&skills=php,css,js,web"

Now as you see each request is dependent on values in the previous request, the way I am doing this is to make 3 AsyncTasks, the first will make a request and when it gets response, the other will start with data from response.

The AsyncTask I am using is this taken from HERE:

class RequestTask extends AsyncTask<String, String, String>{

    @Override
    protected String doInBackground(String... uri) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response;
        String responseString = null;
        try {
            response = httpclient.execute(new HttpGet(uri[0]));
            StatusLine statusLine = response.getStatusLine();
            if(statusLine.getStatusCode() == HttpStatus.SC_OK){
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                responseString = out.toString();
                out.close();
            } else{
                //Closes the connection.
                response.getEntity().getContent().close();
                throw new IOException(statusLine.getReasonPhrase());
            }
        } catch (ClientProtocolException e) {
            //TODO Handle problems..
        } catch (IOException e) {
            //TODO Handle problems..
        }
        return responseString;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        //Do anything with response..
    }
}

My question is: what is the best way to do this, is there any way to do it using a php file that will handle all the requests, or is there any class or function in Android to do this the correct way, or my way is the only solution?

Note: The user_meta_vars I am updating are custom fields added by me and can't be filled with data when requesting a registration.

Thank you all

Community
  • 1
  • 1
Salam El-Banna
  • 3,784
  • 1
  • 22
  • 34

0 Answers0