# Facebook

![facebook-ads-logo.png](https://assets.relyanceuat.xyz/images/docs/11998556638605/12008224442509.png)
Facebook ads are run exclusively through Facebook's advertising platform. It can help a business get more visibility for their Facebook content and boost traffic to their core website content.
The Relyance Facebook integration requires a developer account in **Meta For Developers** page before using the Marketing API.

In order to integrate Facebook with Relyance AI you will need a **Client ID**, **Client Secret**, and **User ID**.

#### In Facebook:

1. Login to your Facebook account.
2. Go to the Meta For Developers page here: [https://developers.facebook.com/docs/marketing-apis/get-started](https://developers.facebook.com/docs/marketing-apis/get-started)
3. It should recognize your logged in user, if not click the **Log In** button at the top right.
4. Create a developer's account by going here: [https://developers.facebook.com/](https://developers.facebook.com/)
5. Click on **My Apps** in the top right corner.
6. Click the **Create App** button.
7. Select **Consumer** for the app type.
8. Continue the wizard by clicking **Next**.
9. Add a meaningful name (e.g. Relyance Scan) and click the **Create app** button.
10. This will create the app and bring you to the App dashboard page. In the section Add products to your app find the **Facebook Login** card and click **Set up**.
11. In the left-hand navigation menu select **Settings** under **Facebook Login**.
12. In the Facebook Login settings page ensure **Client OAuth login** and **Web OAuth login** are both set to **Yes**. Paste **https://root.relyance.ai/api/oauth2** into the **Valid OAuth Redirect URIs** input box.
13. Click **Save changes**.
14. Open the **Settings** dropdown in the left-hand navigation and select the **Basic** menu item.
15. Copy the **Client ID** ( **App ID**) and **Client Secret** ( **App secret** ) to be used in Relyance.
16. In the next part you'll need to obtain the **User ID**. Start by going here: [https://developers.facebook.com/tools/explorer/](https://developers.facebook.com/tools/explorer/)
17. In the left side, select your newly created app in the **Meta App** dropdown.
18. In **User or Page** dropdown select **Get User Access Token**.
19. Under **Permissions** click on the dropdown to check all permissions you want under the **User Data Permissions** section.
20. Click **Generate Access Token**. The box on top of the blue big button is populated with the access token.
21. Click the **Submit** button at the top to get your **USER ID**.
22. This will output your ID and Name. Copy the **USER ID** (id) to be used in Relyance.
```json
{
  "id": "1512345678986",
  "name": "Boutique Integration"
}
```

![Facebook-3.png](https://assets.relyanceuat.xyz/images/docs/11998556638605/13756840919821.png)

![Facebook-4.png](https://assets.relyanceuat.xyz/images/docs/11998556638605/13756840808845.png)

![Facebook-5.png](https://assets.relyanceuat.xyz/images/docs/11998556638605/13756820847245.png)

![Facebook-6.png](https://assets.relyanceuat.xyz/images/docs/11998556638605/13757045921165.png)

![Facebook-7.png](https://assets.relyanceuat.xyz/images/docs/11998556638605/13757294409357.png)

#### In the Relyance AI application:

1. Login to your Relyance account.
2. Navigate to the **Settings** Menu in the bottom left-hand side.
3. Select **Integrations**.
4. Click on the **Vendor Integration** tab.
5. Find the **Facebook** integration card and click it to open its connections.
6. Under **Authentication Method**, choose **Oauth2 / User Access Token**.
8. Paste the **Client ID**, **Client Secret**, and **User ID** into their respective fields. The **API Version Number** can be left as-is.

![Facebook-1.png](https://assets.relyanceuat.xyz/images/docs/11998556638605/12008325755149.png)

9. Click **Authenticate**.
10. At this point, you should see the following result on the **Vendor** Integrations page:

![Facebook-2.png](https://assets.relyanceuat.xyz/images/docs/11998556638605/12008325756941.png)

11. Congratulations, you are now connected to **Facebook**.

<!-- failure-modes:begin (generated from the integration catalog; do not hand-edit) -->

## If the connection reports Connected but returns nothing

These are the ways this integration comes back empty without reporting an error. Generated from the integration catalog, so it tracks what the connection actually asks for.

1. **Authorised, then empty.** The connection carries an authorisation, not a password: it stops returning data if the account that granted it loses access, its own permissions narrow, or the grant is revoked at the vendor. None of that reports an error here -- the connection keeps its last status until the next scan.
2. **A credential rotated at the vendor is not picked up here.** **Client Secret** is stored when you save the connection, so regenerating the value at the vendor breaks the next scan until it is re-pasted here. Recording the expiry on the connection means Relyance warns you before it lapses.

<!-- failure-modes:end -->

<!-- terraform-examples:begin (generated from the integration catalog; do not hand-edit) -->

## Manage this integration with Terraform

Connections for this integration can be managed as code with the [Relyance Terraform provider](https://registry.terraform.io/providers/Relyance/relyance/latest). Non-secret fields go in `auth.params`; secret fields go in `auth.secrets_wo`, which is write-only — never stored in Terraform state. Rotate secrets by bumping `auth.secrets_wo_version`.

The **OAuth (browser authorization)** method uses a browser authorization flow, so the connection is created in the Relyance app. Manage it in Terraform afterwards by importing it (`terraform import relyance_integration_connection.example facebook/<connection_id>`) or reading it with the `relyance_integration_connection` data source.

<!-- terraform-examples:end -->
