【发布时间】:2017-07-25 16:40:45
【问题描述】:
数据库:MongoDB 后端框架:CodeIgniter
想从后端管理默认用户表。我正在使用 ParseRestAPI,但众所周知,Mongodb 不允许在没有会话的情况下更新用户。那么有什么方法可以管理 App 创建的用户并删除/创建新用户。
【问题讨论】:
标签: php mongodb rest codeigniter parse-platform
数据库:MongoDB 后端框架:CodeIgniter
想从后端管理默认用户表。我正在使用 ParseRestAPI,但众所周知,Mongodb 不允许在没有会话的情况下更新用户。那么有什么方法可以管理 App 创建的用户并删除/创建新用户。
【问题讨论】:
标签: php mongodb rest codeigniter parse-platform
是的,您可以使用 Parse Rest API 做到这一点
例如删除用户: 使用 DELETE http 动词并调用类似的东西:
注意:您需要传递 Session Token 或 Master Key
curl -X DELETE \
-H "X-Parse-Application-Id: YOURAPPID" \
-H "X-Parse-REST-API-Key: YOURAPIKEY" \
-H "X-Parse-Session-Token: SESSIONTOKEN" \
-H "X-Parse-Master-Key: YOURMASTERKEY" \
https://api.example.com/1/users/<objectId>
在php中你可以写:
$ch = curl_init('https://api.example.com/1/users/<objectId>');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-Parse-Application-Id: YOURAPPID',
'X-Parse-REST-API-Key: YOURAPIKEY',
'X-Parse-Master-Key: YOURMASTERKEY'
);
$result = curl_exec($ch);
要创建一个用户调用这样的 API(例如我使用 curl)
curl -X POST \
-H "X-Parse-Application-Id: YOUAPPID" \
-H "X-Parse-REST-API-Key: YOURAPIKEY" \
-H "Content-Type: application/json" \
-d '{ "objectId": "", "updatedAt": "", "createdAt": "", "name": "John Doe", "pass": "toto42" }' \
https://api.example.com/1/classes/User/
【讨论】: