Can't create a new row in using Parse in android. I am able to retrieve, but when I try to add a new row like this, I keep getting false and new row is not being created.
What am I doing wrong here ?
I am exactly following what is given in Parse-Android documentation.
ParseObject storyActivity = new ParseObject("StoryActivity");
storyActivity.put("createdByUser", user);
storyActivity.put("story", story);
storyActivity.put("type", likeUnlike);
return storyActivity.saveInBackground().isCompleted();
Check class level permission Write under class StoryActivity's Security on console.
Call that in following way -
ParseObject storyActivity = new ParseObject("StoryActivity");
storyActivity.put("createdByUser", user);
storyActivity.put("story", story);
storyActivity.put("type", likeUnlike);
storyActivity.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
// your object is successfully created.
} else {
//error occurred
Toast.makeText( context,e.getMessage().toString(),Toast.LENGTH_LONG );
}
}
});
So, by this toast message you can know what is reason of problem you are getting.
Try on this way to set read write permission when user insert/ update record in parse database like ...
ParseObject storyActivity = new ParseObject("StoryActivity");
storyActivity.put("createdByUser", user);
storyActivity.put("story", story);
storyActivity.put("type", likeUnlike);
// here first set read write permission like ..
// when user update value ya insert new value in database
ParseACL postACL = new ParseACL(ParseUser.getCurrentUser());
postACL.setPublicReadAccess(true);
postACL.setPublicWriteAccess(true);
storyActivity.setACL(postACL);
storyActivity.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
// success
} else {
// fail
Log.e("Tag", "getting to fail " + e.getMessage());
}
}
});
Related
I'm using Parse with Android in order to sync my data.
I'm trying to delete an object which is stored in the Parse cloud via
The callback returns and there's no exception, the Logcat message is "deleted".
But the object still exists in table when I check the Parse Data.
tastToEdit is an object from Task class (configured locally in my app).
ParseObject parse_task = new ParseObject("Task");
parse_task.put("Description",tastToEdit.getDescription());
parse_task.put("DueDate",tastToEdit.getDueDate());
parse_task.put("Priority",tastToEdit.getPriority().ordinal());
int com_state = (tastToEdit.getCompleted()) ? 1 : 0;
parse_task.put("IsCompleted",com_state);
parse_task.put("Location",0);
parse_task.put("Category",tastToEdit.getTask_catg().ordinal());
parse_task.put("Status", tastToEdit.getTask_sts().ordinal());
//parse_task.deleteInBackground();
parse_task.deleteInBackground(new DeleteCallback() {
public void done(ParseException e) {
if (e == null) {
Log.d("msg","deleted");
} else {
Log.d("msg", "not deleted");
e.printStackTrace();
}
}
});
What might be causing the callback to return as "deleted" but the object still remains?
Thanks in advance.
You are creating a new ParseObject and you try to delete it after but you don't provide an ObjectID.
A better way to do this will be to first do a ParseQuery for that task you are looking and the in the completion delete it.
I am using parse for my data in android app. for some reason the code inside query.findInBackground is not getting executed.
public List<Date> sessionHeaderFetch(){
Log.d("test", "session fetch entry");
ParseQuery<Sessions> query = ParseQuery.getQuery(Sessions.class);
final List<Date> sessionHeaders = null;
query.findInBackground(new FindCallback<Sessions>() {
#Override
public void done(List<Sessions> sessionsObjects, com.parse.ParseException e) {
Log.d("test", "session internal entry");
if (e == null) {
Log.d("test", "Retrieved " + sessionsObjects.size() + " sessions");
for (Sessions session : sessionsObjects) {
sessionHeaders.add(session.getNetsDate());
};
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
Log.d("test", "session last value");
return sessionHeaders;
}
the code inside public void done() is not all invoked.
I don't think you have understood how to query correctly in Parse.
When you define the parse query. The get query should contain the name of the table that you are trying to query. Also the queries returned will be ParseObjects normally, so I would expect that your callback should be new FindCallback().
I've adjusted the parse query below.
ParseQuery<Sessions> query = ParseQuery.getQuery("ParseTableName");
final List<Date> sessionHeaders = null;
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> sessionsObjects, com.parse.ParseException e) {
Log.d("test", "session internal entry");
if (e == null) {
// Find succeeded, so do something
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
Obviously you will need to replace "ParseTableName" with the name of the table that you are trying to query in parse.
I actually solved it by using an ArrayList, there were some problems with the List initialization and also the results are fetched asynchronous manner so my functions which calls these functions were getting null values so I had to write by calling functions that calls the parse fetch functions asynchronously as well.
but the query can be written like this and it works.
public void sessionFetch(Date headers, final ParseIOListener<Sessions> listener){
ParseQuery<Sessions> query = ParseQuery.getQuery(Sessions.class);
Log.d("test", "input header" + headers );
query.whereEqualTo("NetsDate",headers);
final ArrayList<Sessions> sessionsData = new ArrayList<Sessions>();
query.findInBackground(new FindCallback<Sessions>() {
#Override
public void done(List<Sessions> sessionsObjects, com.parse.ParseException e) {
if (e == null) {
for (Sessions session : sessionsObjects) {
Log.d("test", "output objects" + session.toString() );
sessionsData.add(session);
Log.d("test", "Retrieved -- sessions" + sessionsObjects.size() );
}
listener.onDataRetrieved(sessionsData);
} else {
listener.onDataRetrieveFail(e);
}
}
});
}
If you want more details on implementing this, check this link
The reason why you feel the code is not being invoked is because you are returning from the method before the ".findInBackground" operation has completed. Remember the query is performed on a background thread. So this is how your code will run:
ParseQuery query = ParseQuery.getQuery(Sessions.class);
final List sessionHeaders = null;
------> 1. query.findInBackground (Popped onto background thread)
return sessionHeaders; (by the time you get here, sessionHeaders will probably still be null).
So change the logic of the code and wait till the callback returns before doing any processing on the "sessionHeaders" object.
I am trying to run a function to update some data in an existing table in parse.com. Below is the function:
private void saveMeToDBnCloud(final LocModel aLocObj)
{
db.addLoc(aLocObj);
ParseQuery<ParseObject> query = ParseQuery.getQuery("tblxxx");
query.getInBackground(myIdInCLoud, new GetCallback<ParseObject>() {
public void done(ParseObject upObj, ParseException e) {
if (e == null)
{
upObj.put("lat", "1");
upObj.put("lng", "2");
upObj.put("geoTime", "3");
upObj.saveInBackground();
Log.d("svcloud","inside func::");
}
else
{
Log.d("svcloud","error::" + e);
}
}
});
}
Note: all columns in the table are String type.
The function is getting called and also getting inside if condition, as its showing the log. But data isn't updating in parse.com.
Any solutions?
SOLVED!!
Just wrote the access permission to write for ACL and its working fine. :-)
I'm having some issues while trying to save a ParseRelation. I've tried creating the ParseUser first (I thought that was the problem) but it continued to happen.
Situation: I have 2 tables, one is User (Parse.com default) and a second one called Teams. Inside the latter, there's a ParseRelation to User. After saveInBackground is triggered I check the DataBrowser and I can see that the team was in fact created but the players added not in the relation.
My code:
ParseObject newTeam = new ParseObject(Constants.TABLE_TEAMS);
newTeam.put(Constants.ATTRIB_TEAM_NAME, nombreEquipo);
// FIXME ParseRelation not being saved
ParseRelation<ParseUser> playersRelation = newTeam
.getRelation(Constants.ATTRIB_TEAM_PLAYERS);
// Get Users from ListView
for (int i = 0; i < invitedPlayers.size(); i++) {
ParseUser pu = (ParseUser) viewPlayerList.getItemAtPosition(i);
playersRelation.add(pu);
Log.d(LOG_TAG,
"Player being added: "
+ pu.get(Constants.ATTRIB_USER_NAME));
}
newTeam.put(Constants.ATTRIB_TEAM_PLAYERS, playersRelation);
newTeam.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
// setResult(RESULT_OK);
Toast.makeText(getApplicationContext(), "Team created.",
Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(getApplicationContext(),
"ParseException: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
Any ideas ? I've read the docs and also checked a few samples but can't seem to find out what's the problem.
Edit: Using Parse.com v1.5.0 and Android 4.4.2
I want to show Facebook Page's Notes items with those comments and likes using Graph API.
To do that, I'm using the asyncFacebookRunner in Facebook SDK.
Steps are like this:
call asyncFacebookRunner.request to get Note Item with PageId
mAsyncRunner.request(sAPIString, new NotesRequestListener(), null);
Response has come. ( I can't highlight function call. Sorry for inconvenient to find it.)
public class NotesRequestListener implements com.facebook.android.AsyncFacebookRunner.RequestListener
{
/**
* Called when the request to get notes items has been completed.
* Retrieve and parse and display the JSON stream.
*/
#Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
Log.i("My_TAG", "onComplete with response, state");
try
{
// process the response here: executed in background thread
final JSONObject json = new JSONObject(response);
JSONArray arrNotesItems = json.getJSONArray("data");
int l = (arrNotesItems != null ? arrNotesItems.length() : 0);
// !!!!
// This has another request call
// !!!!
final ArrayList<WordsItem> newItems = WordsItem.getWordsItems(arrNotesItems,getActivity());
WordsActivity.this.runOnUiThread(new Runnable() {
public void run() {
wordsItems.clear();
wordsItems.addAll(newItems);
aa.notifyDataSetChanged();
}
}); // runOnUiThread
} // try
catch (JSONException e)
{
Log.i("My_TAG", "JSON Error in response");
} // catch
} // onComplete
... other override methods ...
} // Request Listener
< Another Class >
public static ArrayList<WordsItem> getWordsItems(JSONArray arrJSON, Activity activity) {
ArrayList<WordsItem> wordsItems = new ArrayList<WordsItem>();
int l = (arrJSON != null ? arrJSON.length() : 0);
try {
WordsItem newItem;
for (int i=0; i<l; i++) {
JSONObject jsonObj = arrJSON.getJSONObject(i);
String sTitle = jsonObj.getString("subject");
String sNoteID = jsonObj.getString("id");
... get another fields here ...
newItem = new WordItem(...);
// !!!!
// This has request call for comments
// !!!!
ArrayList<CommentItem> arrComment = getUserComments(sNoteID);
wordsItems.add(newItem);
}
} catch (Exception e) {
e.printStackTrace();
}
return wordsItems;
} // getWordsItems
call another asyncFacebookRunner.request to get comments of item(with NoteID)
in getUserComments
mAsyncRunner.request(sAPIString, new CommentRequestListener(), null);
Before getting comments(OnComplete in CommentRequestListener has not called), getWordsItems returns item array.
So I can't see the comments.
How can I wait to update UI till getting comments?
(It's so ironic to synchronize asynchronized calls.)
Thanks in advance.
Use facebook object which has non-asynchronous request method.
You need not implement listener method.
So, I suggest below means.
use mAsyncRunner.request for first request call.
use mFacebookRunner.request for second request call.
I hope it may help you:-)
Using FQL - Facebook Query Language you can easily get all this information about any particular note info
, Also to get likes on that and comments over it as like examples given in the links.