I'm trying to request the products from Magento using REST-API for Android
I've create the authentication using Scribe. I read that is not meant for Android, therefore, I searched more and found signpost.
here is my code
private void requestOAuth(String url)
{
OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(MAGENTO_API_KEY, MAGENTO_API_SECRET);
consumer.setTokenWithSecret(getAccessToken().getToken(), getAccessToken().getSecret());
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new SigningInterceptor(consumer))
.build();
final Request request = new Request.Builder()
.url(url).build();
try
{
Request signedRequest = (Request) consumer.sign(request).unwrap();
Call call = client.newCall(signedRequest);
Logger.i(TAG, ">>>> oAuth URL = " + url);
Response response = call.execute();
String responseString = response.body().string();
Logger.i(TAG, "oAuth = " + response.code() + " oAuth Request ___ response = " + responseString);
}
catch (OAuthMessageSignerException | OAuthExpectationFailedException | OAuthCommunicationException | IOException e)
{
Logger.e(e);
}
}
I always get "Service temporary unavailable" and code 500.
I activated the guest to test it, and I found out that I have to send header "accept
" > "application/json
", otherwise it does not work as guest.
I've tried that while requesting with authentication, but it responded with something like "user role not available".
I've done the part in Magento where I create a role, give it permission..etc. (hence authentication is done and I've token and token secrete).
Can anyone suggest why it doesn't work? I've been searching for days and trying a lot of things now, and nothing worked...
Is there any header that I must send?