How to update the user object in back4app?

扶醉桌前 提交于 2019-12-02 12:18:23

Yes, their API Reference is very helpful! On this section, there's a "try on JSFiddle" button, have you already seen that?

To update a user object, you must use the Master Key. On the frontend, it's not recommended, and it's better to create a cloud code function and call it on your frontend. However, for test purposes, you can keep using the API Reference, but on JSFiddle, you need to do some changes, here is their sample code, but with the adjustments:

Parse.serverURL = 'https://parseapi.back4app.com';
Parse._initialize('<your-appID-here>', '<your-JSKey-here>', '<Your-MasterKey-here>');

const MyCustomClass = Parse.Object.extend('User');
const query = new Parse.Query(MyCustomClass);

query.equalTo("objectId", "<object-ID-here>");
query.find({useMasterKey: true}).then((results) => {

  if (typeof document !== 'undefined') document.write(`ParseObjects found: ${JSON.stringify(results)}`);
  console.log('ParseObjects found:', results);
}, (error) => {
  if (typeof document !== 'undefined') document.write(`Error while fetching ParseObjects: ${JSON.stringify(error)}`);

  console.error('Error while fetching ParseObjects', error);
});

You'll need to insert the "_" before the "initialize" in your "Parse._initialize" and insert the Master Key in your query as I did on the query.find.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!