Reputation: 2609
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.
Upvotes: 1
Views: 415