Magento oauth with Android

I am using scribe library for android registration with Magento.

But I am getting the error:

org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<p>The requested URL /oauth/initiate was not found on this server.</p>

      

But my key, secret and url are correct. I have correctly defined the user and roles.

I took the link here: https: //gmartinezgil.wordpress.com/2013/08/05/using-the-magento-rest-api-in-java-with-scribe/

My code looks like this, calling Asyntask from an activity: new OauthAsyncTask().execute();

and then my task:

public class OauthAsyncTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {

            try {
                // oauth for magento api access
                OAuthService service = new ServiceBuilder()
                        .provider(MagentoThreeLeggedOAuth.class)
                        .apiKey(MAGENTO_API_KEY)
                        .apiSecret(MAGENTO_API_SECRET)
                        .build();

                Token requestToken = service.getRequestToken();

                String authorizationUrl = service.getAuthorizationUrl(requestToken);

                Verifier verifier = new Verifier("Getting TOken");

                Log.e("authorizationUrl:", authorizationUrl);


                Token accessToken = service.getAccessToken(requestToken, verifier);

                Log.e("accessToken:", accessToken.toString());


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

                Log.e("response:", response.toString());

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


            return null;
        }
    }

      

// auth class

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

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

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

    @Override
    public String getAuthorizationUrl(Token token) {
        return null;
    }


    }

      

Please help me to solve this problem.

+3


source to share


1 answer


The problem is stupid but complicated, I asked my Magento developer that in the BASE-URL he answered " http://myapp.com/ " and got stuck with the problem above, when I searched more about it, I found that some users, using a BASE URL like " http://myapp.com/magento " or " http://myapp.com/magento/index.php " etc. So I found that the real path was " http://myapp.com/index.php ", it was not bound to the BASE address . Therefore, some moments when the product is in development mode, such problems arise and just confirm with magento dev what is the exact path.



+2


source







All Articles