2014-10-16 42 views
0

已在API上使用此示例創建組。以PHP返回值的API

$response = $soap->createGroup(

array(

'api_key'=> $api_key, 
'group_name'=> 'Fred' 
) 

); 

這個效果很好。然而。我需要讓API返回組ID。該API表示,以下

createGroup 
- Usage: Used to create a group that a recipient can be placed in. 
- Return: The id of the created group, used in such functions as addRecipient 
- Parameters 
o group_name (required), your reference to the group, e.g. ‘Group 1’ 
o add_recipients (optional), the id or an array of existing recipient ids to add to this group, see 
addRecipient 

我怎樣才能做到這一點在PHP,這樣我可以添加必要的收件人到這個組,嘗試添加收件人需要以下時。

addRecipient 
- Usage: Used to add a recipient to your account 
- Return: The id of the added recipient 
- Parameters 
o email (required), the recipients email address 
o name (optional), the recipient's name 
o group (optional), id of an existing group, see createGroup. 

它需要組ID而不是名稱。

非常感謝您的幫助,因爲這一直困擾着我。

Louk

+0

是什麼'$ response'是什麼樣子?組ID應該在那。 – 2014-10-16 21:52:49

+0

我試着迴應它並得到這個'可捕捉的致命錯誤:類stdClass的對象無法轉換爲字符串/var/www/vhosts/icanpromo.co.uk/httpdocs/API/Add.php 31行' – 2014-10-16 21:59:15

+0

使用print_r($ response)代替 – 2014-10-16 22:00:26

回答

0

我假設你用Audiolock API工作。

獲得從響應您createGroup查詢組ID,然後使用該值在addRecipient查詢:

# $response is the response from your createGroup query 
$addRecipResponse = $soap->AddRecipient(
    'email' => '[email protected]', 
    'group' => $response, 
    'api_key' => $api_key ## may be needed, may not be 
); 
# the response is the ID of the recipient 
$recip_id = $addRecipResponse($response->response); 
+0

啊頂級男人現在就試試吧! – 2014-10-16 22:04:23

+0

可悲的是,仍然無法正常工作....它會插入收件人,但不會將其添加到組中。 – 2014-10-16 22:08:36

+1

將'group'=> $ gid更改爲'group'=> $ response,它工作正常!好一個!! – 2014-10-16 22:16:03