将属性保存在从查询中获取的用户上(即,不在currentUser上) [英] Saving attributes on a user fetched from a query (i.e. not on the currentUser)
问题描述
我有兴趣根据我的currentUser
执行的操作将属性保存到数据库中的用户.根据以下代码,我收到错误消息除非通过登录或注册对用户进行身份验证,否则无法保存用户"
I am interested in saving attributes to users in the database based on actions that are performed by my currentUser
. Based on the following code, I get the error message "User cannot be saved unless they have been authenticated via logIn or signUp"
NSString *IDToFetch = @"some_id";
PFQuery *query = [PFUser query];
[query whereKey:@"user_id" equalTo:IDToFetch];
PFUser *foundUser = (PFUser *)[query getFirstObject];
foundUser[@"new_column"] = @"Some text";
[foundUser saveEventually]; //here an exception is thrown
我想知道是否有解决方法,可以在不登录该用户的情况下将属性保存到foundUser
.感谢您的帮助!
I was wondering if there is a work around to this where I could save attributes to the foundUser
without having to log that user on. Thanks for your help!
推荐答案
如果要更新当前不是已登录用户的用户,则需要使用master-key
调用Parse.
If you want to update a user that is not currently the logged in user you will need to call Parse using the master-key
.
例如,您可以从CloudCode做到这一点;
You can do this from CloudCode for example;
Parse.Cloud.define('editUser', function(request, response) {
var userId = request.params.userId,
newColText = request.params.newColText;
var User = Parse.Object.extend('_User'),
user = new User({ objectId: userId });
user.set('new_col', newColText);
Parse.Cloud.useMasterKey();
user.save().then(function(user) {
response.success(user);
}, function(error) {
response.error(error)
});
});
并从您的iOS项目中调用它;
and calling it from your iOS project;
[PFCloud callFunction:@"editUser" withParameters:@{
@"userId": @"someuseridhere",
@"newColText": @"new text!"
}];
这篇关于将属性保存在从查询中获取的用户上(即,不在currentUser上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!