cancel
Showing results for 
Search instead for 
Did you mean: 

when retriving magento token on android getting this error

when retriving magento token on android getting this error

I am getting these error when retrieving magento token using scribe library oauth on android. org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: 'oauth_problem=parameter_absent&oauth_parameters_absent=oauth_verifier'

My source code

 public class Test extends AppCompatActivity {

    final String MAGENTO_API_KEY = "7c852d9f72dbd3e860d7cb0b7ef0fda5";
    final String MAGENTO_API_SECRET = "b6a6afc52b065811915824259cb1efa7";
    final String MAGENTO_REST_API_URL = "http://myhost.com/api/rest";

    private static Token requestToken;
    private OAuthService service;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);

// To override error of execution of network thread on the main thread
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        try {

            service = new ServiceBuilder()
                    .provider(MagentoThreeLeggedOAuth.class)
                    .apiKey(MAGENTO_API_KEY)
                    .apiSecret(MAGENTO_API_SECRET)
                    .debug()
                    .build();

            System.out.println("Magento'srkflow");
            System.out.println();

            // Obtain the Request Token
            System.out.println("FetchingRequest Token...");
            requestToken = service.getRequestToken();
            System.out.println("GotRequest Token!");
            System.out.println();

            System.out.println("FetchingAuthorization URL...");
            String authorizationUrl = service.getAuthorizationUrl(requestToken);
            Log.d("DEBUG", authorizationUrl);
            System.out.println("GotAuthorization URL!");
            System.out.println("Nownd authorize Main here:");
            System.out.println(authorizationUrl);
            System.out.println("Ande the authorization code here");
            System.out.print(">>");

            String verifierCode = ((EditText) findViewById(R.id.tt)).getText().toString();
            Log.d("DEBUG", verifierCode);
            System.out.print("LP" + verifierCode);
            Verifier verifier = new Verifier(verifierCode);
            System.out.println();
            System.out.println("TradingRequest Token for an Access Token...");
            Token accessToken = service.getAccessToken(requestToken, verifier);
            System.out.println("GotAccess Token!");
            System.out.println("(if curious it looks like this: "
                    + accessToken + " )");
            System.out.println();

            OAuthRequest request = new OAuthRequest(Verb.GET, MAGENTO_REST_API_URL + "/products");
            service.signRequest(accessToken, request);
            Response response = request.send();
            System.out.println();

            System.out.println(response.getCode());
            System.out.println(response.getBody());
            System.out.println();


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


    }


    public static final class MagentoThreeLeggedOAuth extends DefaultApi10a {
        private static final String BASE_URL = "http://myhost.com/";

        @Override
        public String getRequestTokenEndpoint() {
            return BASE_URL + "oauth/initiate";
        }

        @Override
        public String getAccessTokenEndpoint() {
            return BASE_URL + "oauth/token";
        }

        @Override
        public String getAuthorizationUrl(Token requestToken) {
            return BASE_URL + "oauth/authorize";
           // return BASE_URL + "admin/oauth_authorize?oauth_token="
            //        + requestToken.getToken(); //this implementation is for admin roles only...
        }

    }
}