2013-08-24 65 views
1

我已被分配为为我的客户网站集成API。该API由vision6.com.au提供。他们的网站上没有太多的信息。任何人都可以给我一个例子,它将联系vision6数据库,并添加从我们的网站使用jQuery和PHP开发的联系人。如何从网站集成JSON API

这里是我想

 
var newVal = { 
    "id": 1, 
    "method": "addUser", 
    "params": [ 
     "APIKEY", 
     "123456", 
     { 
      "username"  : "username_123", 
      "password"  : "123456abc", 
      "first_name" : "First Name", 
      "last_name" : "Last Name", 
      "email"  : "[email protected]", 
      "mobile"  : "0412312312", 
      "phone"  : "56565656", 
      "fax"   : "57575757", 
      "position"  : "Manager", 
      "is_read_only" : true, 
      "timezone"  : "Australia/Brisbane", 
      "email_user" : true, 
      "is_confirmed" : true 
     } 
    ] 
}; 

$.ajax({ 
    url: 'http://www.vision6.com.au/api/jsonrpcserver.php?version=3.0', 
    type: 'POST', 
    beforeSend: function(){alert('sending');}, 
    data: newVal, 
    //dataType: 'json', 
    //data: JSON.stringify(newVal), 
    //contentType: 'application/json; charset=utf-8', 
    dataType: 'json', 
    //async: false, 
    success: function(msg) { alert(msg); 

    } 

}); 

的方式这是我从他们的文档 developers.vision6.com.au采取

+0

它是一个编程问题?如果是,请尝试提供有关您以功能签名的形式提及的API的信息。然后将其翻译成http://api.jquery.com/jQuery.get/调用。 –

回答

0

你需要下载一个jsonRPCClient.php并将它包含在你的php文件中。从我与Vision6 API的交流来看,它并不是很全面,在开始深入研究之前没有什么意义。不幸的是,他们对你的入门并不是很有帮助。

我的代码,让你开始

include 'includes/jsonRPCClient.php';  
$list_id = 1234; 
$url = "http://www.vision6.com.au/api/jsonrpcserver.php?version=3.0"; 
$apikey = 'YOURAPIKEYHERE' 
$api = new JsonRpcClient($url); 
    $contact = array(); 
    $contact[] = array(
     'First Name' => "John", 
     'Email' => "[email protected]"  
    ); 

$returnID = $api->addContacts($apikey, $list_id, $contact); 

我发现的最重要的变化是

$api->addContacts($apikey, $list_id, $contact); 

使用API​​遵循这种结构

$api ->APIMethod($apikey, $OtherRequiredFields/Arrays);  
0

我建议按照他们的文档

http://developers.vision6.com.au/3.0/guide/getting-started

文档提到了一个客户端库来访问他们的JSON-RPC。下载它,创建一个免费帐户,并从他们的例子中生成一段PHP代码。它似乎也包含很多见解和例子。我只是引用PHP代码addbatch

// setup vars 
$list_id01  = 123; 
$list_id02  = 456; 
$message_id = 111; 
$batch_details = array 
(array 
    ('list_id'  => $list_id01, 
    'type'   => 'list',  // all Contacts in List 123 
    'time'   => 'send,  // populate Batch time of send 
) 
array 
    ('list_id'  => $list_id02, 
    'type'   => 'contact',  // send to contact_list, next 
    'contact_list' => array(2),array(17),array(18), 
    'time'   => 'send,  // populate Batch time of send 
)); 
$queue_id = $api->invokeMethod('addBatch', $message_id, $batch_details, 
time() + (24*3600), true); 

一旦你产生的代码,不会授权请求,一个简单的动作片段,但表现为你的预期,你应该在SO更新你的问题。即你应该发布摘录和你得到的结果与你期望得到的结果。这可能真的有助于解决这个问题。

我也建议直接联系服务支持。

PS

除非你将能够问形式的问题,这将是对其他用户的潜在有用的,这将是很困难的,你寻求答案。否则你的问题可以被认定为太局部化了

1

对于那些谁希望所有的方法使用Ruby进行集成,我用一个简单的代码创建了一个要点:

require 'httparty' 

url = 'http://www.vision6.com.au/api/jsonrpcserver.php?version=3.0' 
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 

JSON.parse(HTTParty.post(url, headers: { 'Content-Type' => 'application/json' }, body: JSON.dump({ 
    'method' => 'getSessionInfo', 'params' => [api_key] 
}))) 

JSON.parse(HTTParty.post(url, headers: { 'Content-Type' => 'application/json' }, body: JSON.dump({ 
    'method' => 'searchLists', 'params' => [api_key] 
}))) 

list_id = 123456 
JSON.parse(HTTParty.post(url, headers: { 'Content-Type' => 'application/json' }, body: JSON.dump({ 
    'method' => 'addContacts', 'params' => [api_key, list_id, [{ 'First Name' => 'Foo', 'Last Name' => 'Bar', 'Email' => '[email protected]' }]] 
}))) 
+0

请将相关代码添加到您的答案中。 – max

+0

上次我做到了,有人问我只包含链接:( –