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



我正在尝试弄清楚如何使用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 inn";
          $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 exceptionn";
            print_r($e);
        }

我认为您滥用了对象属性"状态"。https://help.bronto.com/bmp/reference/r_api_soap_contactfilter.html,如果您查看此页面,它会显示状态等于的所有事物。老实说,我认为最好使用此过滤器功能来选择未订阅的用户并根据过滤器的结果执行逻辑。$contact->状态 == "取消订阅"返回什么?我的意思是,总是有这种 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";
        }

我刚刚注意到你的运算符不对。 你有"=",不应该是"=="吗?

相关内容

  • 没有找到相关文章

最新更新