In my application I am trying to retreve data from server using api.Since I was trying to get the facebook data I am passing facebookid when i call the url for the first time.The code is suchthat it should get data from the server when another url is called.
My problem is that I am getting a null value when I call the url for the second time.That is here the session is getting deleted.
My code is given below.
public void getdetails(){
JSONObject json = JSONfunctions.getJSONfromURL(unielement+"UserLogin.php?faceid="+facebookID);
System.out.println(unielement+"UserLogin.php?faceid="+facebookID+" "+json);
try{
JSONArray data = json.getJSONArray("data");
//Loop the Array
for(int i=0;i < data.length();i++){
ArrayList<String> list = new ArrayList<String>();
list.add(data.getJSONObject(0).getString("CreditBySelf"));
list.add(data.getJSONObject(0).getString("CreditThroughFriend"));
list.add(data.getJSONObject(0).getString("ForUser"));
list.add(data.getJSONObject(0).getString("LDrawTicket"));
list.add(data.getJSONObject(0).getString("Buy-In"));
list.add(data.getJSONObject(0).getString("RemVote"));
list.add(data.getJSONObject(0).getString("Voted"));
StringBuilder sb = new StringBuilder();
for (String s : list)
{
sb.append(s);
sb.append("\t");
}
uid = list.get(0);
name = list.get(1).toString();
System.out.println(list);
textView_name1.setText(name);
}
}
catch(JSONException e1){
Toast.makeText(getBaseContext(), "No name Found"+e1 ,Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
}
}
When I call the above function a session is created and it should be there when I call the below code.
public void getdataforsharing(){
JSONObject json = JSONfunctions.getJSONfromURL(unielement+"userfbaction.php");
System.out.println(unielement+"userfbaction.php "+json);
try{
JSONArray wholedata = json.getJSONArray("data");
System.out.println(wholedata);
JSONObject data = wholedata.getJSONObject(0);
System.out.println(data);
//Loop the Array
for(int i=0;i < data.length();i++){
list1 = new ArrayList<String>();
/*list1.add(data.getJSONObject(0).getString("wall_image"));
list1.add(data.getJSONObject(0).getString("wall_title"));
list1.add(data.getJSONObject(0).getString("wall_Description"));*/
list1.add(data.getString("wall_image"));
list1.add(data.getString("wall_title"));
list1.add(data.getString("wall_Description"));
StringBuilder sb = new StringBuilder();
for (String s : list1)
{
sb.append(s);
sb.append("\t");
}
System.out.println("Share on facebook"+list1.get(0));
}
}
catch(JSONException e1){
Toast.makeText(getBaseContext(), "No name Found"+e1 ,Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
}
}
When I call this function I am not getting the session that is created by the first funcion and I am getting a null data.
What is wrong in this?Anyone help me please.
The session is created in “UserLogin.php”.
Sessions are controlled in PHP by use of a SessionID which can be either:
Your code is doing neither: you’re only accepted the JSON back, you’re not reading in the cookie and sending next time, nor are you receiving a SessionID in the data and using it with the next call.
Easiest solution in your case: