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"}';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作