[How To] Developing Apps for Android

I can’t get it worked. I decided to use your library.

Does it work only minSdk = 21? My app minSdk 15, if I override it, is it ok?

Try it.

It uses :

1 Like

I have tried scribejava v.4.1.2 same in your library, it works well.

FYI:
I also tried scribejava v.5.3.0 (latest), it failed to authorize frappe Oauth. I can’t get it worked, just back to v.4.1.2.

I guess 5.3.0 requires later android API

Hi revant_one,

I have followed your library guideline. request GET works fine but I can’t POST with parameter. It returns Internal Server Error. There’s a method I can get request POST worked.
URL: [POST] 0.0.0.0:8000/api/method/frappe.integrations.oauth2.revoke_token Params: token = access_token

final AuthReqCallback responseCallback = new AuthReqCallback() {
                @Override
                public void onSuccessResponse(String s) {
                    try {
                        JSONObject openID = new JSONObject(s);
                        Log.i("responseCallback", s);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onErrorResponse(String s) {

                }
};

AccessTokenCallback

    AuthReqCallback accessTokenCallback = new AuthReqCallback() {
                    @Override
                    public void onSuccessResponse(String s) {
                        Log.d("CallbackSuccess", s);
                        JSONObject bearerToken;
                        try {
                            bearerToken = new JSONObject(s);
                        } catch (JSONException e) {
                            bearerToken = new JSONObject();
                        }
                        if(bearerToken.length() > 0){
                            try {
                                final url = "https://IP/api/resource/Employee";
                                final OAuthRequest request = new OAuthRequest(Verb.POST, url);
                                request.addParameter("employee_name", "abc");
                                request.addParameter("date_of_joining", "2016-10-10");                                   
                                request.addParameter("date_of_birth", "1990-10-10");
                                request.addParameter("gender", "Male");
                                authRequest.makeRequest(bearerToken.getString("access_token"), request, responseCallback);

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }

                    @Override
                    public void onErrorResponse(String s) {
                        Log.d("CallbackError", s);
                    }
                };

getAuthToken

 void getAuthToken(final Account account, final AuthReqCallback callback) {
            accMan.getAuthToken(account, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS,
                    null, this, new AccountManagerCallback<Bundle>() {
                        @Override
                        public void run(AccountManagerFuture<Bundle> future) {
                            try {
                                Bundle bundle = future.getResult();
                                String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
                                callback.onSuccessResponse(authToken);
                                Log.d("bearerToken", authToken);
                                accMan.invalidateAuthToken(account.type, authToken);
                            } catch (Exception e) {
                                Log.d("error", e.toString());
                            }
                        }
                    }, null);
        }

Try using request.addBodyParameter instead of request.addParameter

Also set appropriate headers for application/x-www-form-urlencoded

1 Like

I overlooked the frappe document and not pay attention to detail, it took my several days to get it worked (shamed me).
We have to wrap json string in data.

request.addBodyParameter(“data”, jsonObject.toString());

Thanks you revant_one, for your value time and answers.

1 Like