首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用WixHive Rest APi创建Wix联系人

使用WixHive Rest APi创建Wix联系人
EN

Stack Overflow用户
提问于 2015-09-02 14:05:59
回答 2查看 886关注 0票数 1

所有人。

我正在为wix.com网站建设者开发仪表板应用程序。

我使用PHP来实现这一点。我尝试使用WixHive和Rest API处理wix联系人

以下是有关这方面的文档:

代码语言:javascript
运行
复制
http://dev.wix.com/docs/wixhive/contacts
http://dev.wix.com/docs/wixhive/using-the-rest-api
http://dev.wix.com/docs/wixhive/rest-api

不幸的是,wix没有php SDK。我基于这个非官方的sdk创建我自己的类:

代码语言:javascript
运行
复制
https://github.com/ransom1538/wix_php_sdk

Get single contact和contacts list非常有用。

但是reconcileContact不能工作。

Return suche错误:

代码语言:javascript
运行
复制
HTTP/1.1 401 Unauthorized
X-Seen-By: sputnik4.aus_dsp
Date: Tue, 01 Sep 2015 08:15:00 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 83
Server: sputnik4.aus

{"errorCode":401,"message":"Bad authentication credentials.","wixErrorCode":-23004}

我使用这个教程实现了签名:

代码语言:javascript
运行
复制
http://dev.wix.com/docs/wixhive/using-the-rest-api#signature

我用这个工具检查了一下:

代码语言:javascript
运行
复制
http://dev.wix.com/docs/infrastructure/signature-tool

我发现签名是匹配的。

我的请求看起来像这样:

代码语言:javascript
运行
复制
URI: 

https://openapi.wix.com/v1/contacts?version=2.0.0&application-id=13ffc79d-ceb8-df76-74e0-3de5b0f29b2d&instance-id=8c4c0505-370a-451b-bd9b-6667f955c26e&timestamp=2015-09-01T12%3A11%3A41.477Z&signature=lkwqWrVFRCAhtpgGjqCn6v3TgUnakiIFKjMog41J-zQ 

Method: POST 

POST Data: {"emails":{"tag":"work","email":"karen_meep@wix.com","emailStatus":"recurring"}}

资料来源:

代码语言:javascript
运行
复制
https://gist.github.com/antonshell/e92cb9cc57e7c8555d3a
EN

回答 2

Stack Overflow用户

发布于 2016-07-12 06:56:24

将请求头version=2.0.0更改为version=1.0.0

票数 1
EN

Stack Overflow用户

发布于 2015-10-24 13:41:56

当您在POST方法中提交json数据时。post请求中应该有content-type标头。因此,您的curl_request方法将是

代码语言:javascript
运行
复制
public function curl_request($method, $uri, $data = '')
{
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $uri);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
   curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
   if ($data != '') {
       curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
   } else {
       curl_setopt($ch, CURLOPT_HEADER, TRUE);
   }
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
   curl_setopt($ch, CURLOPT_TIMEOUT, 45);
   if ('POST' == $method)
   {
     curl_setopt($ch, CURLOPT_POST, TRUE);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
   }
   else if ('PUT' == $method)
   {
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
   }
   else if('GET' != $method)
   {
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
   }
   $response = curl_exec($ch);
   $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
   $body = substr($response, $header_size);
   return $body;

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32345709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档