如何通过rest api parse.com设置ajax调用

时间:2013-05-16 20:57:58

标签: api rest unix parse-platform

我是rest api的新手,我正在尝试使用api rest将文件关联到对象:

curl -X POST \
  -H "X-Parse-Application-Id: qS0KL*9lFLE**S3VMk" \
  -H "X-Parse-REST-API-Key: nh3***MhcKJIfIt1Gm" \
  -H "Content-Type: application/json" \
  -d '{
        "name": "Andrew",
        "picture": {
          "name": "...profile.png",
          "__type": "File"
        }
      }' \
  https://api.parse.com/1/classes/PlayerProfile

有人能解释我如何设置ajax调用吗?什么是“name”:“andrew”?这是一个名为andrew的列在我的播放器配置文件中吗?

这是我对api的实现,但是服务器回复了我错误的请求400

$.ajax({
    type: 'POST',
    headers: {'X-Parse-Application-Id':'qS0KLMx5h9lFLG**yhM9EEPiTS3VMk','X-Parse-REST-API-
                Key':'nh3G8D**hcKJIfIt1Gm','Content-Type': 'application/json'},
    url: "https://api.parse.com/1/users",
    data: {
        "username": "francesco",
        "picture": {
            "name": "b3b47ce2-62dc-4861-a0ad-79cfffe9b07a-foto ste.jpg",
            "__type": "File"
        }
    },

    contentType: "application/json",

    success: function(data) {
        console.log(data );
    },

    error: function(data) {
        console.log("ko" );
    }
});

我的实现中api -d可能是错误的。-d中的curl是什么意思?

1 个答案:

答案 0 :(得分:0)

本指南中的示例显示了如何在单个请求中创建新的PlayerProfile对象并将其与文件关联。由于您要更新现有用户(而不是创建新用户),因此您需要使用Update REST API请求格式。使用PUT而不是POST,然后通过将对象ID附加到端点URL来指定您引用的用户:https://api.parse.com/1/users/ {objectId}。