解析:以编程方式创建新类

时间:2016-01-11 06:02:00

标签: class parse-platform schema command-line-interface

是否可以通过任何API或Parse CLI以编程方式(即不是从仪表板)创建新类?

REST API似乎具有获取,修改和删除单个模式(类)但不添加它们的功能。 (https://parse.com/docs/rest/guide#schemas)。

希望得到以下内容:

curl -X ADD \
-H "X-Parse-Application-Id: XXXXXX" \
-H "X-Parse-Master-Key: XXXXXXXX" \
-H "Content-Type: application/json" \
https://api.parse.com/1/schemas/City

1 个答案:

答案 0 :(得分:2)

您似乎跳过了处理文档中添加架构的部分。要创建新类according to documentation,请在cURL中使用以下方法:

curl -X POST \
  -H "X-Parse-Application-Id: Your APP Id" \
  -H "X-Parse-Master-Key: Your master key" \
  -H "Content-Type: application/json" \
  -d ' 
    {
      "className": "Your Class name goes here", 
      "fields": {
        "Your field name here": {
          "type": "Your field's data type e.g. String, Int etc. Add multiple fields if you want"
        }
      }
    }' \
  https://api.parse.com/1/schemas/[Your class name]

或者在Python中:

import json,httplib
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('POST', '/1/schemas/Game', json.dumps({
       "className":"[Your class name]","fields":{"Your field name":{"type":"your field's data type"} }
     }), {
       "X-Parse-Application-Id": "7Lo3U5Ei75dragCphTineRMoCfwD7UJjd1apkPKX",
       "X-Parse-Master-Key": "ssOXw9z1ni1unx8tW5iuaHCmhIObOn4nSW9GHj5W",
       "Content-Type": "application/json"
     })
result = json.loads(connection.getresponse().read())
print result