通过 API 将电子邮件和姓名传递给 GetResponse

问题描述

亲爱的 Stack 好人。我有一个自定义 PHP 网站,想寻求帮助,将新用户的姓名和电子邮件传递到我的 GetResponse 列表。我目前有一个 Mailchimp 集成,效果很好,但想为 GetResponse 重写它(请参阅下面的代码)。

我已咨询过此文档,但无法做到:https://apidocs.getresponse.com/v3/case-study/adding-contacts

有人可以帮我修改它以与 GetReponse 一起使用吗?我将不胜感激。

\Unirest\Request::auth('Arsen','MAILCHIMP_API_KEY');

$body = \Unirest\Request\Body::json([
    'email_address' => $_POST['email'],'merge_fields' => [
        'LNAME' => $_POST['name']
    ],'status' => 'subscribed'
]);

\Unirest\Request::post(
    'MAILCHIMP_LINK' . '/lists/' . 'MAILCHIMP_API_LIST' . '/members',[],$body
);

先谢谢你!

解决方法

请参阅下面的代码,这对我有用。我开发它是为了收集用户的实际 IP 地址(本示例中未显示)。 API URL 很重要:应该以 /contacts(下面的 $url)结尾,但这在 Getresponse 文档中不太清楚。我不确定 Getresponse 中是否有“状态”字段,因此我没有包含该字段(一旦添加到联系人,状态将被订阅)。

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

void file(string country[],double vaccinations[]);
void highest(string country[],double vaccinations[]);
void lowest(string country[],double vaccinations[]);
void average (string country[],double vaccinations[]);
void welcomeMessage();

int main() {
    //declare variables and arrays,set vaccinations and countries arrays to 127 for the number of countries,amd subsequent vaccination data
    string countries[127];
    double vaccinations[127];
    file(countries,vaccinations);
      
    //call wecome message function
    welcomeMessage();
    //calls function to count highest vaccination rate and country names
    highest(countries,vaccinations);
    cout << endl;
    //calls function to count lowest vaccination rate and country name
    lowest(countries,vaccinations);
    //calls function to print the average vaccination rate
    //average(countries,vaccinations);
}

void welcomeMessage() {
    cout << "Welcome to the vaccine data analysis program!" << endl;
    cout << endl;
    cout << "This program will print which country currently has admistered the most COVID-19 vaccine doses per 100 people" << endl;
    cout << endl;
    cout << "The program will also print which country currently has administered the least,per 100 people,as well as the average dose administration per 100 people,out of 127 countries on the list." << endl;
    cout << endl;
}

void file(string country[],double vaccinations[]) {
    int index = 0;
    ifstream inFile;
    inFile.open("vaccinations.txt");
    if (!inFile.is_open()) {
        cout << "Unable to open file." << endl;
    } else {
        while (index < 127) {
            //add code to isolate country string
            inFile >> country[index];
            //add code to isolate vaccination percentage
            inFile >> vaccinations[index];
            index++;
        }
    }
}

void highest(string country[],double vaccinations[]) {
    string highestCountry = country[0];
    int highestTotal = vaccinations[0];

    for (int i = 1; i < 127; i++) {
        if (vaccinations[i] > highestTotal) {
            highestTotal = vaccinations[i];
            highestCountry = country[i];
        }
    }
    cout << highestCountry << " has the highest number of vaccinations at " << fixed << setprecision(100) << highestTotal << " per 100 people." << endl;
}


void lowest(string country[],double vaccinations[]) {
    string lowestCountry = country[0];
    int lowestTotal = vaccinations[0];

    for (int i = 1; i < 127; i++) {
        if (vaccinations[i] < lowestTotal) {
            lowestTotal = vaccinations[i];
            lowestCountry = country[i];
        }
    }
    cout << lowestCountry << " has the lowest number of vaccinations at " << fixed << setprecision(100)<< lowestTotal << " per 100 people." << endl;
}