Saving user causes object not found error - objective-c

Saving a user causes Error: object not found for update (Code: 101, Version: 1.2.19)
[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
if (!error) {
[PFUser currentUser].location = geoPoint;
[[PFUser currentUser] save];
}
}];
what am I doing wrong?
http post request https://api.parse.com/2/update
{
"iid": "[redacted]",
"classname": "_User",
"data": {
"email": "test#test.com",
"objectId": "[redacted]"
},
"session_token": "[redacted]",
"v": "i1.2.19",
"uuid": "[redacted]"
}
response
{
"code": 101,
"error": "object not found for update"
}

I have the same problem as you, I done some testing and figure out root cause:
Create new class GameScore as document
Do the same create and update object and find out it works well
Check the "ACL" columns and compare to your problem data. See?
Works ACL, I done modify for * to make it clear
Failed ACL.
As you could see the write privilege lock to user "6iIv5XWZvM", that's why your update will "not found object"
You could change data record directly to "*" to let your update works well.
OK! Here is solution as follow:
Change every record "ACL" data col as follow:
{"*":{"write":true,"read":true}}
You need login PFUSer as specific user to change ACL to public. For my case use objectId will be "6iIv5XWZvM". I need set password and login info and use code to login and modify it. Detail iOS code as follow:
//iOS Sample
[PFUser logInWithUsernameInBackground:#"USERNAME" password:#"PASSWORD" block:^(PFUser *user, NSError *error) {
if (user) {
PFQuery *query = [PFQuery queryWithClassName:CLASS_NAME];
[query findObjectsInBackgroundWithBlock:^(NSArray *objs, NSError *error) {
for (PFObject *obj in objs) {
PFACL *defaultACL = [PFACL ACL];
[defaultACL setPublicReadAccess:YES];
[defaultACL setPublicWriteAccess:YES];
[obj setACL:defaultACL];
[obj saveInBackground];
}
}];
} else {
// The login failed. Check error to see why.
}
}];
However remember to add following setting before you save new data, if you don't want to happen anymore (note: it will be security concern)
//It is iOS code sample.
PFACL *defaultACL = [PFACL ACL];
[defaultACL setPublicReadAccess:YES];
[defaultACL setPublicWriteAccess:YES];
[PFACL setDefaultACL:defaultACL withAccessForCurrentUser:YES];

Try this, i'm using this, when i need to save objects for the current user. Hope it will help.
PFUser *user = [PFUser currentUser];
[user setObject:geoPoint forKey:#"location"];
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(#"Error %# %#", error, [error userInfo]);
}
}];

The error : "object not found for update" append when the you try to save an object that the user does not have ACL access.
In order to let the user change the object you need to set PFACL permission when you create the object :
For a specific user :
PFObject *object = /*the object you want to save*/
NSString *userID = /*the objectID of the user you want to let perform modifications later*/
PFACL *groupACL = [PFACL ACL];
[groupACL setWriteAccess:YES forUserId:userID];
object.ACL = groupACL;
For a all users :
PFObject *object = /*the object you want to save*/
NSString *userID = /*the objectID of the user you want to let perform modifications later*/
PFACL *groupACL = [PFACL ACL];
[groupACL setPublicWriteAccess:YES];
object.ACL = groupACL;

Related

Permissions for a new user / Parse-server-Heroku

I just created a new user on parse-server/Heroku. Using code like this:
PFUser *x = [[PFUser alloc] init];
x.username = #"XXX";
x.password = #"yyyy";
x.email = #"email123#abc.com";
[x signUpInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
if (succeeded) {
NSLog(#"kensu registration ALL OK!!!!");
} else if (error) {
NSLog(#"kensu registration error: %#",error);
}
}];
The user creation went fine. And I can log in witn this new user.
The problem comes after.
When I log in with the new user, I am not allowed to make any update on my mongoDB.
I get this kind of error message:
[Error]: Permission denied for action update on class ....
If I log with the unique user I had before, I can update without any problem. Why?
I looked at the user collection to see any difference, then tried a few things, but without success.
I hope someone can point me in the right direction.

I want to create a ViewController where user can change there existing password. I m using Parse API

PFUser *user = [PFUser currentUser];
// I can see the details of the users when this is called including password
if (user) {
if ([_login_txtpassword.text isEqualToString:user[#"UserPasswrod"]]) {
user[#"userPassword"] = _login_txtnewpassword.text;
[user saveInBackground];
NSLog(#"done");
}
}
this code is not working.... i have put blocks to test my code ... it doesnt pass the if statement
A little conflict in my concepts related parse (so consider me as a noob)
P.S i have read the documentation and search internet but couldnt find a solution.
Many Many thanks in advcance
The right way to do this is to try to log the user in with the old password, then set the new password if successful. (notice this code uses the parse User password attribute, not #"userPassword" as in the OP code, which won't work under any circumstances)...
NSString *username = [PFUser currentUser].username;
NSString *oldPassword = self.oldPasswordTextField.text;
NSString *newPassword = self.newPasswordTextField.text;
[PFUser logInWithUsernameInBackground:username password:oldPassword
block:^(PFUser *user, NSError *error) {
if (user) {
user.password = newPassword;
[user saveInBackground];
} else {
// update UI to tell user that the old password is incorrect
}
}];
Actually you can't override the password of the current user directly from your ViewController. The user should request a new password, that will by sent to his/her email by Parse.
PFUser *currentUser = [PFUser currentUser];
NSString *userEmail = [NSString stringWithFormat: #"%#", currentUser.email];
[PFUser requestPasswordResetForEmailInBackground:userEmail];
or
[PFUser requestPasswordResetForEmailInBackground:self.userEmailTextfield.text];

Facebook Open Graph startForPostWithGraphPath returning "FACEBOOK_NON_JSON_RESULT" = true

I'm trying to configure an Open Graph post. I've followed the code examples on the FB developer site, and, using a test_user, a post is supposedly successfully generated. Here is my code:
- (void)createOGObjectForImage:(NSURL *)imageURL
{
NSMutableDictionary<FBGraphObject> *object =
[FBGraphObject openGraphObjectForPostWithType:#"ogminigame:mini_game"
title:#"Mini Game"
image:#"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:imageURL
description:#""];
[FBRequestConnection startForPostWithGraphPath:#"me"
graphObject:object
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"Result: %#", [result description]);
[self createOGActionWithResult:result];
} else {
NSLog(#"Error posting the Open Graph object to the Object API: %#", error);
[self sharePhotoWithShareDialog:self openGraphAction:nil];
}
}];
}
However, nothing is appearing on the test user wall. When I step through the code, I can see that when I create the OG object, the result has the following contents:
"FACEBOOK_NON_JSON_RESULT" = true;
More specifically, it looks like this:
So when I create my Action, when I try to retrieve the objectID using:
NSString *objectId = [result objectForKey:#"id"];
it obviously returns nil. Am I missing a stage with the result object? I've tried searching for similar problems but there doesn't seem to be much in the way of an explanation.
Well, it seems the code supplied on the Facebook developer site where you supply your custom stories is incorrect. Namely, it should look like:
- (void)createOGObjectForImage:(NSURL *)imageURL
{
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPostWithType:#"ogminigame:mini_game"
title:#"Mini Game"
image:#"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:imageURL
description:#""];
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"Result: %#", [result description]);
[self createOGActionWithResult:result];
} else {
NSLog(#"Error posting the Open Graph object to the Object API: %#", error);
[self sharePhotoWithShareDialog:self openGraphAction:nil];
}
}];
}
So you cast the dictionary to an FBOpenGraphObject, rather than an FBGraphObject and call startForPostOpenGraphObject instead of startForPostWithGraphPath.
It seems to me Facebook need to be a bit more consistent with their documentation.
I still have nothing showing on the test_account page, but at least the above doesn't seem to be the cause of the issue...

Parse.com -- PFFile is null

So I'm retrieving an object that has a file as one of it's fields. In the Parse.com data browser the file is there and downloads. However, when I retrieve the object, PFFile *wordlistFile = [object objectForKey:kWSWordlistFilesFileKey]; is returning null, and so getDataInBackgroundWithBlock does nothing.
Here's the log of the object I'm retrieving. There is no reference to the file:
2013-12-03 12:07:10.635 WSPhoto[24958:a0b] object = <WordlistFiles:lRHFmHaPRg:(null)> {
ACL = "<PFACL: 0xd445670>";
language = Spanish;
}
And here's the full code. It appears I'm doing everything correctly based on some examples I've seen:
PFQuery* wordlistFilesQuery = [PFQuery queryWithClassName:kWSWordlistFilesClassKey];
[wordlistFilesQuery whereKey:kWSWordlistFilesLanguageKey equalTo:language];
[wordlistFilesQuery includeKey:kWSWordlistFilesFileKey];
[wordlistFilesQuery setCachePolicy:kPFCachePolicyNetworkOnly];
[wordlistFilesQuery getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (!error) {
PFFile *wordlistFile = [object objectForKey:kWSWordlistFilesFileKey];
NSLog(#"******* wordlistFile = %#",wordlistFile);
// Show HUD view
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[appDel showGlobalProgressHUDWithTitle:#"Loading wordlist. This may take a while."];
[wordlistFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
// Super private stuff here
}
// The data didn't load
else {
NSLog(#"loadWordlistFromDBByFile -- wordlist does not exist, loading by querying");
[self loadWordlistFromDBByQuery:language];
}
} progressBlock:^(int percentDone) {
}];
}
// The object didn't load
else {
NSLog(#"loadWordlistFromDBByFile -- wordlist does not exist, loading by querying");
[self loadWordlistFromDBByQuery:language];
}
}];
Make sure your kWSWordlistFilesFileKey is exactly the same as the name of the column seen on the data browser on Parse.com.
So if the column is called "wordlistfile", make sure:
kWSWordlistFilesFileKey = #"wordlistfile";
OK, this was a silly error. I reloaded the WordlistFiles class in the Parse.com Data Browser, and the file disappeared. Not sure how it happened. I swear to you guys I was staring it in the face. I re-uploaded and now it's retrieving, and there doesn't seem to be any weird behavior where it's deleting it.
Operator error.

Google Drive API - list specific files in a specific folder using Objective-C

I'm working on a Google Drive integration for iOS and I've hit a snag—I need to check for the existence of a file in a folder, but I keep getting a "500 Internal Error" response no matter how I seem to put together the request. I think this should be legit:
// self.directoryDriveFile.identifier is a valid folder identifier retrieved on previous request
GTLQueryDrive *query = [GTLQueryDrive queryForChildrenListWithFolderId:self.directoryDriveFile.identifier];
// add query to specify the file we're interested in (works in Java version...)
query.q = [NSString stringWithFormat:#"title='%#' and trashed=false",
ZTCloudSyncLockFileName];
// stopping in debugger shows query.q: title='sync.lock' and trashed=false
// fire off request
[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *files,
NSError *error) {
if (error == nil) {
if ([files.items count] > 0) {
self.foundLockfile = YES;
} else {
self.foundLockfile = NO;
}
} else {
DLog(#"An error occurred loading lockfile request: %#", error);
[self bailWithError:error performCleanup:NO];
}
}];
When the query is executed, it always ends up in error, with the following unfortunately sparse error information:
Error Domain=com.google.GTLJSONRPC
ErrorDomain Code=500 "The operation couldn’t be completed. (Internal Error)"
UserInfo=0x99c4660 {
error=Internal Error,
GTLStructuredError=GTLErrorObject 0x99c4360: {
message:"Internal Error" code:500 data:[1]},
NSLocalizedFailureReason=(Internal Error)}
I've also tried the following more basic query, specifying a parents clause, but I end up with the same unfortunately spare error object shown above:
GTLQueryDrive *altQuery = [GTLQueryDrive queryForFilesList];
altQuery.q = [NSString stringWithFormat:#"title='%#' and trashed=false and '%#' in parents",
ZTCloudSyncLockFileName,
self.directoryDriveFile.identifier];
That, too, should work, but also produces a 500 error.
Additional information: tested the following while working on this:
Check for folder in directory root—OK
Create folder in directory root—OK
Check for file named sync.lock in directory root—OK
-(void)fetchGoogleDriveFileListWithfolderId:(NSString *)folderId
:(void (^)(NSMutableArray *, NSError*))completionBlock
{
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q =[NSString stringWithFormat:#"'%#' in parents and trashed=false", folderId];
GTLServiceTicket *ticketListing = [self.driveService
executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFileList *files, NSError *error)
{
NSMutableArray *mainArray=[[NSMutableArray alloc]init];
if (error == nil)
{
completionBlock(files.items,nill);
}
else
{
NSLog(#"An error occurred: %#", error);
completionBlock(nil,error);
}
}];
}
You can use above method for fetch the folder contents.
Here folderId is
“root” (Main Drive)
“sharedWithMe” for shared folder
GTLDrivefile identifier value