I am using scribe library to register android with Magento.
But I am getting 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 all are correct. I defined user and roles correctly.
I took reference from here:https://gmartinezgil.wordpress.com/2013/08/05/using-the-magento-rest-api-in-java-with-scribe/
My code is like this:
calling Asyntask from activity: new OauthAsyncTask().execute();
and then my task is:
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 out on this issue.
Problem is silly but tricky, I asked my Magento developer that what is the BASE URL he replied with "http://myapp.com/" and got stuck with above problem, when I searched about it more, I found that some users using 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 directed to BASE URL. So some times when product is in development mode these kind of problems occur and just confirm with magento dev's what is exact path.