1

I am trying to get get access token from Magento Oauth from Android using signpost.For this I used the below code.

    final String MAGENTO_API_KEY = "xxxxxxxxxxxxxxxxxxx";
    final String MAGENTO_API_SECRET = "xxxxxxxxxxxxxxxxxxxxx";

    final String OAUTH_INIT_URL = "http://ip/magento/oauth/initiate/";
    final String ACCESS_TOKEN_URL = "http://ip/magento/oauth/token/";
    final String AUTHORIZE_URL = "http://ip/magento/admin/oAuth_authorize/";

    CommonsHttpOAuthConsumer consumer;
    CommonsHttpOAuthProvider provider;
    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if( Build.VERSION.SDK_INT >= 9){
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
            }
        setContentView(R.layout.activity_main);

        new OauthConnectAsync().execute();    
    }

    public class OauthConnectAsync extends AsyncTask <String, Void, String>{
        protected void onPreExecute() {
            super.onPreExecute();

        }
        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub

            try {

                consumer = new CommonsHttpOAuthConsumer(MAGENTO_API_KEY, MAGENTO_API_SECRET);
                provider = new CommonsHttpOAuthProvider(OAUTH_INIT_URL,ACCESS_TOKEN_URL, AUTHORIZE_URL);   
                provider.setOAuth10a(true);
                provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
            } catch (OAuthMessageSignerException | OAuthNotAuthorizedException
                    | OAuthExpectationFailedException
                    | OAuthCommunicationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Log.d("Tokens" , consumer.getToken() + " -- " + consumer.getTokenSecret());

            return null;
        }
        protected void onPostExecute(String file_url) {


        }

But the code give me a 404 not found error as follows.

08-11 10:10:27.692: W/System.err(1860): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Service provider responded in error: 404 (Not Found)

When I used the url http://localhost/magento/oauth/initiate in my Firefox RESTClient got the response As

oauth_problem=parameter_absent&oauth_parameters_absent=oauth_consumer_key

I Can't find the error in my Android code, I would really appreciate any help,I am stuck on this from last few days. Please tell me if I need change anything.

Remees M Syde
  • 2,564
  • 1
  • 19
  • 42
  • Hi @Remees I need this code for requesting the magento for android – Amarnath Baitha Aug 26 '14 at 12:17
  • 1
    @Amarnath Baitha, the code is not working for me, so break the oauth and connected using httpget/pot from android – Remees M Syde Aug 26 '14 at 12:28
  • Actually I am new to this magento I have to do API_KEY,API_SECRET and whatever You used above.So If you have sample then it would be better for me – Amarnath Baitha Aug 26 '14 at 12:41
  • The code is only this much, you have to do some configuration in magento Admin. Try the below tutorial. It wont give me the result but may help you. http://gmartinezgil.wordpress.com/2013/08/05/using-the-magento-rest-api-in-java-with-scribe/ – Remees M Syde Aug 26 '14 at 12:49
  • Dude. Did you just post your API key/secret in your question? If so, delete, edit it out, then flag for a mod to delete revisions to your question. Jeez, dude. This is an indication that you post your questions too hastily. Spend some time on them prior to posting. Helps prevent autobans. –  Nov 14 '14 at 15:06
  • @Will, hi dude its just a sample value, still I am appreciating and respecting you and i changed it, Thank you very much...... – Remees M Syde Nov 15 '14 at 05:29
  • @RemeesMSyde can you please help me here : http://stackoverflow.com/questions/34589538/shipping-charges-are-not-working-in-andriod-app-for-magento-site – fresher Jan 04 '16 at 11:09

0 Answers0