doulachan8217 2014-07-01 14:19
浏览 35
已采纳

Parse.com - PHP添加查询 - 密钥用户标识的ivalid类型

Hi I am trying to do a query to Parse. com and I use right parameters, but I receive from JSON response this: {"code":111,"error":"invalid type for key userid, expected *_User, but got string"}

Here is the code:

 $url = 'https://api.parse.com/1/classes/Tasks';   
 $headers = array(  
   "Content-Type: application/json",  
   "X-Parse-Application-Id: " . $appId,  
   "X-Parse-REST-API-Key: " . $restKey  
 );  
 $objectData = '{"userid":"hQsxiherY2", "tasktitle":"my first title", "taskcontent":"my first content"}';  
 $rest = curl_init();  
 curl_setopt($rest,CURLOPT_URL,$url);  
 curl_setopt($rest,CURLOPT_POST,1);  
 curl_setopt($rest,CURLOPT_POSTFIELDS,$objectData);  
 curl_setopt($rest,CURLOPT_HTTPHEADER,$headers);  
 curl_setopt($rest,CURLOPT_SSL_VERIFYPEER, false);  
 curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);  
 $response = curl_exec($rest);  
 echo $response;   
 curl_close($rest); 

Something is wrong in $objectData->userid maybe I don't send something right... Anyone who use Parse. com and knows where is my mistake ? What I have to send ?

  • 写回答

1条回答 默认 最新

  • douji9734 2014-07-01 22:13
    关注

    Your userid column is actually a pointer, not a string column for the ID. That is the correct way to link objects.

    When you query using a pointer you need to create a pointer properly.

    Instead of a string ID "hQsxiherY2" you need to declare a pointer to the _User class:

    {"__type":"Pointer","className":"_User","objectId":"hQsxiherY2"}
    

    So in your code above your full $objectData would be:

    $objectData = '{"userid":{"__type":"Pointer","className":"_User","objectId":"hQsxiherY2"}, "tasktitle":"my first title", "taskcontent":"my first content"}';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?