5

我的问题是针对 iContact API 的。我已经注册了一个应用程序并获取了 API id。但我找不到 accountId 和 clientFolderId。

请参阅以下链接:

http://developer.icontact.com/documentation/request-your-accountid-and-clientfolderid/ 在上面的页面“在帐户资源上执行 GET”我如何执行此操作以获取帐户 ID 和 clientfolderid。

4

4 回答 4

2

这是我获取帐户 ID 和客户端文件夹 ID 的完整代码,感谢上面的 Carlos Duran 解决了我的一些代码问题:

/* iContact LIVE * /
$GLOBALS['iContact_settings'] = array(
    'apiUrl'   => 'https://app.icontact.com',
    'apiPage'  => '/icp/a/',
    'username' => 'username',
    'password' => 'password',
    'appId'    => 'appId'
);
/* iContact SANDBOX */
$GLOBALS['iContact_settings'] = array(
    'apiUrl'   => 'https://app.sandbox.icontact.com',
    'apiPage'  => '/icp/a/',
    'username' => 'username-beta',
    'password' => 'password',
    'appId'    => 'appId'
);
/**/


$icontact_url  = $GLOBALS['iContact_settings']['apiUrl'] . $GLOBALS['iContact_settings']['apiPage'];
$icontact_page = $GLOBALS['iContact_settings']['apiPage'];
$icontact_headers = array( 
    "GET ".$icontact_page." HTTP/1.0",
    "Accept: text/xml",
    "Content-Type: text/xml",
    "API-Version: 2.2",
    "API-AppId: " .    $GLOBALS['iContact_settings']['appId'],
    "API-Username: " . $GLOBALS['iContact_settings']['username'],
    "API-Password: " . $GLOBALS['iContact_settings']['password']
);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $icontact_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $icontact_headers);

$data = curl_exec($ch);
curl_close($ch);

$account_id = "";
if (($pos=strpos($data,"<accountId>"))!==false){
    $account_id = substr($data, strlen("<accountId>")+$pos);
    if (($pos=strpos($account_id,"<"))!==false){
        $account_id = substr($account_id, 0, $pos);
    }
}


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $icontact_url ."$account_id/c/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $icontact_headers);

$data = curl_exec($ch);
curl_close($ch);

$client_folder_id = "";
if (($pos=strpos($data,"<clientFolderId>"))!==false){
    $client_folder_id = substr($data, strlen("<clientFolderId>")+$pos);
    if (($pos=strpos($client_folder_id,"<"))!==false){
        $client_folder_id = substr($client_folder_id, 0, $pos);
    }
}

我刚刚切换到 JSON,好多了。

$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $icontact_url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, $icontact_headers);

$data = curl_exec($handle);
curl_close($handle);

$decoded = json_decode($data);
$account_id = $decoded->accounts[0]->accountId;

$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $icontact_url ."$account_id/c/");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, $icontact_headers);

$data   = curl_exec($handle);
curl_close($handle);

$decoded = json_decode($data);
$client_folder_

id = $decoded->clientfolders[0]->clientFolderId;

并使用:

"Accept: application/json",
"Content-Type: application/json",

而不是text/xml上面。

于 2012-01-17T03:55:46.287 回答
2

我找到的最简单的方法:登录沙盒或您的真实 iContact 帐户,在主菜单中转到联系人 -> 注册表单,然后创建任何表单,单击查看 HTML,您将在那里找到帐户 ID。

于 2011-10-12T13:40:45.560 回答
1

使用 iContact API 的唯一方法是将正确的标头发送到服务器,然后您将能够发出文档中出现的任何请求和操作。

我发现做到这一点的最好方法是使用 cUrl 设置 PHP 脚本

     $url = "https://app.sandbox.icontact.com/icp/a/";
     $page = "/icp/a/";
     $headers = array( 
        "GET ".$page." HTTP/1.0",
        "Accept: text/html",
        "Content-Type: text/html",
        "API-Version: 2.2",
        "API-AppId: yourapiappid",
        "API-Username: yourapiusername",
        "API-Password: yourappidpassword"
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $data = curl_exec($ch);

在这里你得到你的 accountId,剩下的只是用这个脚本调用正确的 url!

希望能给你一个提示。

“保持良好的编码。”

于 2012-01-06T21:23:42.177 回答
0

这个 PHP iContact API 相当有用https://github.com/icontact

于 2012-12-10T15:32:42.900 回答