# Facebook Response Gatherer

The FastStats Facebook Response Gatherer (FFRG) collects campaign responses from Facebook and stores them in the Social database, making them available in PeopleStage reports.

## Installation

The Facebook Response Gatherer installer is in the `DigitalIntegration.zip` file in the [Apteco Software Releases](<https://portal.apteco.com/software-releases>) area of the Apteco portal.

1. Extract `DigitalIntegration.zip` to the PC where you want the response gatherer to run.
2. Run `FacebookResponseGatherer64Setup.msi` and follow the installation wizard.

The default installation directory is `C:\Program Files\Apteco\FastStats Facebook Response Gatherer x64`. Install in your FastStats application files directory on the FastStats Application Server for the best results. The gatherer can also run on any PC in your system.

## Configuration

After installation, edit `FacebookResponseGatherer64.exe.config` in the installation directory to update the following settings:

- Connection string for the Social database (`SO_`)
- Connection string for the Control database (`WS_`)
- Bulk Insert directory

XML

```xml
<configuration>
  <add key="db_connection_facebook" value="Data Source=localhost;Initial Catalog=SO_AcmeInc;User Id=faststats_service;Password=N0tARealPassw0rd!;"/>
  <add key="db_connection_users" value="Data Source=localhost;Initial Catalog=WS_AcmeInc;User Id=faststats_service;Password=N0tARealPassw0rd!;"/>
  <add key="db_bulkinsert_directory" value="C:\FastStats\Publish\AcmeInc\bulkinserts\"/>
  <add key="db_connection_timeout" value="1200"/>
  <startup/>
</configuration>
```

> [!NOTE]
>
> Run Notepad as Administrator to save changes to files within `Program Files`.

## Folder structure

Create a folder structure to store the files used with the Response Gatherer. You can use any location and naming convention, but you must reference the directories in the batch file.

A typical structure inside the FastStats directory:

The bulk insert directory must be reachable from the SQL Server, and the user running the SQL Server Service must have read permissions on it.

It's standard practice to place the batch file and a `Logs` subdirectory in a folder called `FFRG` within the FastStats base directory. Create the `Logs` subdirectory manually before running the batch file for the first time.

## Running the Response Gatherer

You invoke the FFRG from a batch file and schedule it using Windows Task Scheduler. The command syntax is:

Text Only

```text
FacebookResponseGatherer64.exe <username> <password> <systemname> "TIMEPERIOD=7D"
```

Where `TIMEPERIOD` specifies how far back to gather responses. For example, `7D` for 7 days, `2M` for 2 months, `48H` for 48 hours.

### Example batch file

Batchfile

```batch
REM - Facebook Response Integration
@echo off
C:
cd C:\FastStats\FFRG
cls
SET FFRG="%ProgramFiles%\Apteco\FastStats Facebook Response Gatherer x64\FacebookResponseGatherer64.exe"
SET LOGFILE="Logs\AcmeInc.txt"
SET LOGFILEDETAILS="Logs\AcmeInc_Details.txt"
echo. >> %LOGFILE%
echo. >> %LOGFILEDETAILS%
echo %date% %time% - Starting FastStats Facebook Response Download >> %LOGFILE%
echo %date% %time% - Starting FastStats Facebook Response Download >> %LOGFILEDETAILS%
echo. >> %LOGFILE%
%FFRG% Administrator . AcmeInc "TIMEPERIOD=7D" >> %LOGFILEDETAILS%
IF ERRORLEVEL 9003 goto FailedException
IF ERRORLEVEL 9001 goto FailedDownload
IF ERRORLEVEL 9000 goto FailedLogin
:OK
echo %date% %time% - FastStats Gathered AcmeInc Facebook Responses OK >> %LOGFILE%
goto Complete
:FailedLogin
echo %date% %time% - FastStats Gatherer Failed - Login Failed >> %LOGFILE%
goto Complete
:FailedDownload
echo %date% %time% - FastStats Gatherer Failed - Downloading from Facebook >> %LOGFILE%
goto Complete
:FailedException
echo %date% %time% - FastStats Gatherer Failed - API Exception >> %LOGFILE%
goto Complete
:Complete
echo %date% %time% - Completed FastStats AcmeInc Facebook Response Download >> %LOGFILE%
```

| Parameter | Description |
| --- | --- |
| `SET FFRG` | Location and name of the FFRG executable |
| `SET LOGFILE` | Location and name of the log file |
| `SET LOGFILEDETAILS` | Location and name of the detailed log file |
| Argument 1 | FastStats system user: must have generated the Facebook Token |
| Argument 2 | FastStats user password: you can now use a single character |
| Argument 3 | System name |
| Argument 4 | Time to gather responses (e.g. `TIMEPERIOD=1W`, `TIMEPERIOD=1D`) |

## Scheduling with Windows Task Scheduler

1. Open **Windows Task Scheduler** from the Start Menu.
2. Select **Create Basic Task**.
3. **Create a Basic Task** step: enter a **Name** and **Description**.
4. **Task Trigger** step: select the trigger interval and enter the start date and time.
5. **Action** step: select **Start a program** and select **Next**.
6. **Start a Program** step: select **Browse**, navigate to the batch file, and select it. Optionally, add the XML configuration filename in the **Add arguments** box.
7. **Summary** step: select **Finish**.

Create a task to run the FFRG as frequently as required:

Once the FFRG is running, responses are available in PeopleStage Facebook Reports immediately.
