how to make rest call with key and secret using md5 in android? but I am getting an error as a response in loginService() method,
error : {"status":"error","message":"Signature mismatch"}.
the steps I followed, Step 1- I made a string "param" for getting hash string using md5(string) method Step 2- called a method loginService() for getting response from web service
Calling code:
{
String param = "name" + first_name + last_name + "email" + email + "facebook_user_id" + facebook_user_id + "location" + location + "zip_code" + zip_code + "birthday" + birthday + "time" + time + "api_key" + api_key;
String signature = md5(param);
Post_Method_Interface commonPost = new CommonPostMethod();
getResponceForParse = commonPost.loginService(
first_name + last_name, email,facebook_user_id, location, zip_code, birthday,time, api_key, signature);
Log.d(">>> GetResponceForParse >>> ",getResponceForParse);
if (!facebook_user_id.equals(null)) {
Post_Method_Interface commonPost = new CommonPostMethod();
getResponceForParse = commonPost
.FacebookLoginModel(first_name + last_name,
email, facebook_user_id, location,
zip_code, birthday, time, api_key,
signature);
Log.d("GetResponceForParse 1", getResponceForParse);
Intent i = new Intent(getApplicationContext(),
HomeActivity.class);
}
loginService() web service method of Post_method_Interface class,
public String loginService(String name, String email,
String facebook_user_id, String location, String zip_code,
String birthday, String timestamp, String api_key, String sig) {
try {
JSONObject schObject = new JSONObject();
schObject.put("name", name);
schObject.put("email", email);
schObject.put("facebook_user_id", facebook_user_id);
schObject.put("location", location);
schObject.put("zip_code", zip_code);
schObject.put("birthday", birthday);
schObject.put("time", timestamp);
schObject.put("api_key", api_key);
schObject.put("sig", sig);
String URL = ApiConstant.URL_FacebookLoginModel;
JsonPostRequest postrequest = new JsonPostRequest();
InputStream is = postrequest.doPost(schObject, URL);
response = postrequest.inputSteamToString(is);
Log.d("Login", response);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return response;
}
md5() method:
private static final String md5(final String parem) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest
.getInstance("MD5");
digest.update(parem.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
String h = Integer.toHexString(0xFF & messageDigest[i]);
while (h.length() < 2)
h = "0" + h;
hexString.append(h);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
Please help me its a very urjent !!!