Bronto PHP API可获取特定电子邮件的特定列表的订阅状态

时间:2019-01-24 20:11:59

标签: php api bronto

我试图弄清楚如何使用PHP和Bronto API来识别用户是否已订阅或取消订阅特定的电子邮件列表。

我正在使用以下代码,但我的问题是,无论该用户是已订阅还是未订阅,我始终会为该用户获得“活动”状态,而我需要查看的不是他们是否在列表中而是未订阅或在列表上并已订阅。

反正知道我应该改变什么?

 <?php
     $client = new SoapClient('https://api.bronto.com/v4?wsdl', array('trace' => 1, 
                             'features' => SOAP_SINGLE_ELEMENT_ARRAYS));

    try {
          //token
          $token = "abc 123 and yz";

          //print "logging in\n";
          $sessionId = $client->login(array('apiToken' => $token))->return;

           $session_header = new SoapHeader("http://api.bronto.com/v4",
               'sessionHeader',
               array('sessionId' => $sessionId));
           $client->__setSoapHeaders(array($session_header));

            // set up a filter to read contacts and match on email address
            $filter = array('email' => array(array('operator' => 'EqualTo',
                   'value' => 'fake.person@gmail.com'
                   ),
               ),
      ); 
            $contacts = $client->readContacts(array('pageNumber' => 1,
                  'includeLists' => false,
                  'filter' => $filter,
                  )
                )->return;

            // print matching contact email addresses
             foreach ($contacts as $contact) {
             //$contact->status  always seems to have a status of active or null ??
              if($contact->status ='subscribed')
             {
                echo " <a href='' class='btn btn-primary'>Unsubscribe</a>";
             }
              else if($contact->status ='Unsubscribed')
             {
               echo " <a href=''>Subscribe</a>";
             }
               //print $contact->email . ': ' . $contact->status . "\n";
            }

          } catch (Exception $e) {
            print "uncaught exception\n";
            print_r($e);
        }

1 个答案:

答案 0 :(得分:0)

我认为您正在滥用对象属性“状态”。如果您查看此页面https://help.bronto.com/bmp/reference/r_api_soap_contactfilter.html,它将显示状态等于的所有事物。 老实说,我认为最好使用此筛选器功能选择未订阅的用户并根据筛选器的结果执行逻辑。$ contact-> status ==“ unsub”返回什么? 我的意思是总是有这种https://help.bronto.com/bmp/reference/r_api_soap_readunsubscribes.html方法来选择未订阅的用户,然后对在该组中找不到的用户执行逻辑。

        // print matching contact email addresses
         foreach ($contacts as $contact) {
         //$contact->status  always seems to have a status of active or null ??
          if($contact->status != 'unsub')
         {
            echo " <a href='' class='btn btn-primary'>Unsubscribe</a>";
         }
          else if($contact->status =='unsub')
         {
            echo " <a href=''>Subscribe</a>";
         }
           //print $contact->email . ': ' . $contact->status . "\n";
        }

我刚刚注意到您的操作员不正确。您有“ =”,不应该是“ ==”吗?