/** * Use MailChimp API key to try to grab corresponding user profile to check validity of key * * @param string * @return bool */ function li_ac_check_invalid_auth_code($consumer_key, $consumer_secret, $access_key, $access_secret) { try { $aweber = new LI_AWeberAPI($consumer_key, $consumer_secret); $account = $aweber->getAccount($access_key, $access_secret); } catch (LI_AWeberAPIException $exc) { if ($exc->type == 'UnauthorizedError') { return TRUE; } else { return FALSE; } /*print "<h3>AWeberAPIException:</h3>"; print " <li> Type: $exc->type <br>"; print " <li> Msg : $exc->message <br>"; print " <li> Docs: $exc->documentation_url <br>"; print "<hr>";*/ } }
/** * Adds a subcsriber to a specific list * * @param string * @param string * @param string * @param string * @param string * @return int/bool */ function push_contact_to_list($list_id = '', $email = '', $first_name = '', $last_name = '', $phone = '') { if (isset($this->options['li_ac_ck']) && $this->options['li_ac_ck'] && $list_id) { try { $aweber = new LI_AWeberAPI($this->options['li_ac_ck'], $this->options['li_ac_cs']); $account = $aweber->getAccount($this->options['li_ac_ak'], $this->options['li_ac_as']); $list_url = "/accounts/" . $account->id . "/lists/" . $list_id; //Check if custom Field Exists $list_custom_fields_url = "/accounts/" . $account->id . "/lists/" . $list_id . "/custom_fields"; $list_custom_fields = $account->loadFromUrl($list_custom_fields_url); $params = array('email' => $email, 'name' => $first_name . $last_name); if (count($list_custom_fields->data['entries'])) { foreach ($list_custom_fields->data['entries'] as $entry) { if ($entry['name'] == 'phone') { $params['custom_fields'] = array('phone' => $phone); break; } } } $list = $account->loadFromUrl($list_url); $subscribers = $list->subscribers; $subscribers->create($params); return TRUE; } catch (AWeberAPIException $exc) { } } return FALSE; }