No authentication challenges found - Volley - android

Hi I am using volley to parse my api, when i pass the valid credentials it works fine gives me ab auth token and if the credentials are wrong i still want it to parse the response but its giving me "No authentication challenges found" and JSONObject response as null response in return. Is it something with volley or it is something with the php script??
private void sendRequest_getAuth(){
try {
JSONObject jsonBody = new JSONObject();
jsonBody.put("phone", "phn in numeric");
jsonBody.put("password", "pswd");
JsonObjectRequest JSONRequest = new JsonObjectRequest(Request.Method.POST, "the api url", jsonBody,
new com.android.volley.Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
jresponse=response;
show_getAuth(jresponse);
}
},
new com.android.volley.Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d("onError_response",jresponse.toString());
Toast.makeText(LoginActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
show_getAuth(jresponse);
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(JSONRequest);
}
required Response which should be parsed:-
{
"errors": [
{
"message": "Invalid Credentials"
}
]
}

Try the following thing:-
Check you Url in Postman (or any applicaiton) and pass invalid credentials and check what response you are receiving from webservice. If you are not getting respose as you have mentioned in you question then its Server side issue (PHP).
Now if you are getting response as above, the kindly check if successfull login and error in login response pattern is same.
Because if the json signature mismatches it won't be able to parse.
If its entering in Error callback kindly mention what is the error server is returning.
Have look at this link too...
java.io.IOException : No authentication challenges found
In case of any doubts, feel free to reply...

Related

Android Volley ParseError: is there any way to get the actual message from the server?

I am getting the following error from a webapi call in an Android app using volley:
org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
And I want to know how to see the exact message from the server as opposed to the Volley error. Here is the code:
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.d(TAG, "onResponse: " + response.toString());
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
if (error instanceof ParseError) {
Log.d(TAG, "onErrorResponse: ParseError: ");
}
}
});
queue.add(request);
It is a really basic call and under most circumstances I get back the jsonobject, but in those cases where the server sends me something different I want to be able to account for it. The error which is thrown is parsing of a value which is not json because it is an error. How can I see what the server is sending from the ErrorListener?

Getting error when trying to upload data to server

I have been trying to upload my data from android to my server using java, volley and laravel but I am getting. BasicNetwork.performRequest: Unexpected response code 500. I have used postman to test my api and it is working perfectly well.
What could be the cause?
Java code
RequestQueue queue = Volley.newRequestQueue(this); // this = context
StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>()
{
#Override
public void onResponse(String response) {
// response
pd.dismiss();
Log.i("error", String.valueOf( response.toString()));
}
},
new Response.ErrorListener()
{
#Override
public void onErrorResponse(VolleyError error) {
// error
Toast.makeText(SignUpActivity.this, "Network Error. Please Try Again.", Toast.LENGTH_LONG).show();;
}
}
) {
#Override
protected Map<String, String> getParams()
{
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("email", email);
parameters.put("password", password);
parameters.put("vCode", vCode);
parameters.put("phone",phone);
return parameters;
}
};
queue.add(postRequest);
Code 500 means that there's a problem at server side. If you're using laravel you should have a web server (as apache, nginx...) which generates error logs.
Check error logs and there you may find what the error is (maybe your app is sending data in a way that server doesn't understand, data is not being sent properly...).
Apache error log location in Linux
Nginx error log location

Get Instagram Stories Json

How can I get Instagram Stories in JSON Object by using Instagram API? I have tried using the following URL, but I am getting this error.
// https://i.instagram.com/api/v1/feed/user/MY_USER_ID/reel_media/
{
"message": "login_required",
"logout_reason": 2,
"status": "fail"
}
Code :
String id = userInfoHashmap.get(InstagramApp.TAG_ID);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, "https://i.instagram.com/api/v1/feed/user/"+id +"/reel_media/?access_token="+mApp.getTOken(), new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.d("ID: ", String.valueOf(response));
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
There is currently no official API for Instagram Stories.
In order to authenticate the request to that unofficial API endpoint, you must send a device 'sessionid', not your Instagram app's access token.
You can read my Medium article describing what you need to make a successful request to retrieve Instagram Stories: https://medium.com/#calialec/chrome-ig-story-bribing-the-instagram-story-api-with-cookies-c813e6dff911
Also, check out my GitHub repo to see where I'm injecting the cookies into the request: https://github.com/CaliAlec/ChromeIGStory/blob/master/event/src/index.js#L167
Have you checked the Instagram API Documentation? It states that you need an access token to make any call to the API. Add your access token as query parameter to your endpoint.

Post request to server not properly working Volley

Hi guys i am facing a problem and the problem is that i am trying to send post request to server and i am getting exception
com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of
when i try to send data through get request it is working properly and when i try to send data through post request i am getting the above exception i have tried searching but not succeeded.
below is my code
JsonObjectRequest _send_cab_data_to_server = new JsonObjectRequest(Request.Method.POST,
cab_Data_Url, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.e("", "response : " + response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e("", "error : " + error.toString());
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("Method", "CarLocation");
params.put("data", _Cab_Locations_In_Driver_Service);
return params;
}
};
// Adding request to request queue
Volley_Controller.getInstance().addToRequestQueue(_send_cab_data_to_server,
"volley");
}
and the data attribute corresponds to a set of strings that are combined
e.g Ï2|33.7129221|73.0634634|Apr28,201510:50:33AM|0ÎÏ2|33.7129272|73.0634653|Apr28,201510:50:58AM|0Î
and the json response is
{
"Success": true,
"Info": "Successful",
"Response": [
{
"Status": "Done"
}
]
}
when i try to send data through get request it is working properly and
when i try to send data through post request i am getting the above
exception
As you said you are getting below exception:
com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of
This means that you are getting null response. You are supposed to use GET method only, not the POST method because your server is not responding to the post request but rather returning a null object and so your parser is getting failed at parsing null object.
FYI, There is a meaning and importance of GET and POST method. Use the appropriate method defined by your server API.

Sending login params to Rails server using Volley

Link to Rails server. https://afternoon-sea-5654.herokuapp.com.
I want to send a simple JSON POST to attempt to login. I get the following volley errors
Error
04-09 14:03:56.156 3002-3031/com.digitalnatives.volleytest E/Volley﹕ [244] BasicNetwork.performRequest: Unexpected response code 500 for https://afternoon-sea-5654.herokuapp.com/sessions/create
04-09 14:03:56.160 3002-3002/com.digitalnatives.volleytest E/Volley﹕ [1] 4.onErrorResponse: Error:
I can't tell if it's down to the way I am formatting the request. Here is an example login request using curl manually.
Login -
curl -X POST -d "user[email]=ywaghmare5203#gmail.com&user[password]=12345678&" https://afternoon-sea-5654.herokuapp.com/sessions/create.json
Request perameter: email, password,
Response Perameter:
{"id":10,"username":"yogeshwaghmare1","email":"ywaghmare5203#gmail.com","password_hash":"$2a$10$pvLhzJlVz8Hl86O7N/ekiO2wrwNxbfTZlYPtccY4f7vXYNFs1vq6a","password_salt":"$2a$10$pvLhzJlVz8Hl86O7N/ekiO","last_login_time":null,"is_active":null,"contact_number":"123456","created_at":"2015-04-01T19:20:37.552Z","updated_at":"2015-04-01T19:20:37.552Z"}
JSONObjectRequest code
public void loginTest() {
private final String LOGIN = "https://afternoon-sea-5654.herokuapp.com/sessions/create";
// Post params to be sent to the server
HashMap<String, String> params = new HashMap<String, String>();
// old test code : params.put("user[email]=test1#gmail.com&", "user[password]=12345678&");
params.put("user[email]", "test1#gmail.com");
params.put("user[password]", "12345678");
JsonObjectRequest req = new JsonObjectRequest(LOGIN, new JSONObject(params),
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
VolleyLog.v("Response:%n %s", response.toString(4));
responseText.setText("Worked!");
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
responseText.setText("Nope");
}
});
// add the request object to the queue to be executed
AppController.getInstance().addToRequestQueue(req);
}
Actually in response you are not Getting the JSON data. It is returning a HTML message regarding redirection. Your response is 302
Response code 500 means its a server sided syntax error. You can test your api through online API testing platform like Runscope. It really save our time and confusion when we collaborate with web team and android team.
Runscope Link

Categories

Resources