### Ruby: Install SDK Source: https://developers.facebook.com/docs/business-sdk/getting-started Install the Meta Business SDK for Ruby using the gem command. Ensure you have rbenv or rvm set up if necessary. ```bash gem install facebookbusiness ``` -------------------------------- ### Ruby: Test SDK Installation Source: https://developers.facebook.com/docs/business-sdk/getting-started Run this command in your terminal to test your Ruby SDK setup. Verify that your project file is correctly configured with your credentials. ```bash ruby test.rb ``` -------------------------------- ### Test Node.js Installation Source: https://developers.facebook.com/docs/business-sdk/getting-started Run your Node.js script using the `node` command to test the SDK installation. This will execute the code in `index.js`. ```bash node index.js ``` -------------------------------- ### PHP: Test SDK Installation Source: https://developers.facebook.com/docs/business-sdk/getting-started Run this command in your terminal to test your PHP SDK installation. Ensure your project file is correctly configured with valid credentials. ```bash php src/test.php ``` -------------------------------- ### Install PHP SDK with Composer Source: https://developers.facebook.com/docs/business-sdk/getting-started Run this command in your terminal within the project folder to install the PHP Business SDK using Composer. ```bash composer install ``` -------------------------------- ### Python: Install SDK Source: https://developers.facebook.com/docs/business-sdk/getting-started Install the Meta Business SDK for Python using pip. It's recommended to use a virtual environment manager like virtualenv, pyenv, or conda. ```bash pip install facebook_business ``` -------------------------------- ### Python: Test SDK Installation Source: https://developers.facebook.com/docs/business-sdk/getting-started Execute this command in your terminal to verify your Python SDK installation. Check that your project file contains the correct API credentials. ```bash python test.py ``` -------------------------------- ### Ruby: Create Project File and Initialize SDK Source: https://developers.facebook.com/docs/business-sdk/getting-started Create a Ruby project file to configure the Facebook Ads API with your access token and app secret. This example fetches and prints campaign names. ```ruby require 'facebookbusiness' FacebookAds.configure do |config| config.access_token = '{access-token}' config.app_secret = '{appsecret}' end ad_account = FacebookAds::AdAccount.get('act_{{adaccount-id}}', 'name') ad_account.campaigns(fields: 'name').each do |campaign| puts campaign.name end ``` -------------------------------- ### Install Node.js Business SDK Package Source: https://developers.facebook.com/docs/business-sdk/getting-started Install the Facebook Node.js Business SDK package using npm. This command adds the SDK as a dependency to your project. ```bash npm install --save facebook-nodejs-business-sdk ``` -------------------------------- ### Create Page Promotion Ad Source: https://developers.facebook.com/docs/business-sdk/common-scenarios/ads-buying Creates an ad campaign to promote a Facebook Page, aiming for increased Page Likes. This example targets the US with a daily budget and focuses on ad impressions. ```javascript require('dotenv').config(); const business_sdk = require('facebook-nodejs-business-sdk'); const AdAccount = business_sdk.AdAccount; const Ad = business_sdk.Ad; const access_token = process.env.ACCESS_TOKEN; const ad_account_id = process.env.AD_ACCOUNT_ID; const adAccount = new AdAccount(ad_account_id); const ads = adAccount.createAd([ 'name', 'adset_id', 'creative', 'status', 'preview_url' ], { 'name': 'Sample Page Promotion Ad', 'adset_id': 'act_YOUR_AD_SET_ID', 'creative': { 'name': 'Sample Creative', 'page_id': 'YOUR_PAGE_ID', 'object_story_spec': { 'page_id': 'YOUR_PAGE_ID', 'instagram_actor_id': 'YOUR_INSTAGRAM_ACTOR_ID', 'link_data': { 'call_to_action': { 'type': 'page_likes' } } } }, 'status': Ad.Status.PAUSED, 'preview_url': true }); ads.then((result) => { console.log(result); }).catch((error) => { console.error(error); }); ``` -------------------------------- ### Get Instagram Professional Account ID Source: https://developers.facebook.com/docs/business-sdk/common-scenarios/instagram-management Retrieve the Instagram Professional Account ID associated with a Facebook Page. This is a prerequisite for publishing content to Instagram. ```text GET graph.facebook.com/v18.0/{instagram-business-account-id}?fields=instagram_business_account ``` -------------------------------- ### Create Java Class to Fetch Campaigns Source: https://developers.facebook.com/docs/business-sdk/getting-started Create a Java class to initialize the SDK, fetch campaign data, and print campaign names. Replace placeholders with your actual credentials. ```java import com.facebook.ads.sdk.APIContext; import com.facebook.ads.sdk.APINodeList; import com.facebook.ads.sdk.AdAccount; import com.facebook.ads.sdk.Campaign; public class TestFBJavaSDK { public static final APIContext context = new APIContext( "{access-token}", "{appsecret}" ); public static void main(String[] args) { AdAccount account = new AdAccount("act_{{adaccount-id}}", context); try { APINodeList campaigns = account.getCampaigns().requestAllFields().execute(); for(Campaign campaign : campaigns) { System.out.println(campaign.getFieldName()); } } catch (Exception e) { e.printStackTrace(); } }} ``` -------------------------------- ### Initialize Node.js Project Source: https://developers.facebook.com/docs/business-sdk/getting-started Initialize a new Node.js project using npm. This command creates a `package.json` file for managing project dependencies. ```bash npm init ``` -------------------------------- ### Python: Create Project File and Initialize SDK Source: https://developers.facebook.com/docs/business-sdk/getting-started Create a Python project file to initialize the Facebook Ads API with your app credentials and ad account ID. This snippet shows how to retrieve and print campaign data. ```python from facebook_business.api import FacebookAdsApi from facebook_business.adobjects.adaccount import AdAccount my_app_id = '{app-id}' my_app_secret = '{appsecret}' my_access_token = '{access-token}' FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token) my_account = AdAccount('act_{{adaccount-id}}') campaigns = my_account.get_campaigns() print(campaigns) ``` -------------------------------- ### PHP: Create Project File and Initialize SDK Source: https://developers.facebook.com/docs/business-sdk/getting-started Create a PHP project file to initialize the Facebook Ads API with your app credentials and ad account ID. This snippet demonstrates how to fetch and display campaign names. ```php getCampaigns(); // Loop over objects foreach ($cursor as $campaign) { echo $campaign->{CampaignFields::NAME}.PHP_EOL; } ``` -------------------------------- ### Modify Node.js Project File to Fetch Campaigns Source: https://developers.facebook.com/docs/business-sdk/getting-started Add this code to your `index.js` file to initialize the SDK, fetch campaign data, and log campaign names to the console. Replace placeholders with your actual credentials. ```javascript const bizSdk = require('facebook-nodejs-business-sdk'); const accessToken = '{access-token}'; const accountId = 'act_{{adaccount-id}}'; const FacebookAdsApi = bizSdk.FacebookAdsApi.init(accessToken); const AdAccount = bizSdk.AdAccount; const Campaign = bizSdk.Campaign; const account = new AdAccount(accountId); var campaigns; account.read([AdAccount.Fields.name]) .then((account) =>{ return account.getCampaigns([Campaign.Fields.name], { limit: 10 }) // fields array and params }) .then((result) =>{ campaigns = result campaigns.forEach((campaign) =>console.log(campaign.name)) }).catch(console.error); ``` -------------------------------- ### Create Composer JSON for PHP SDK Source: https://developers.facebook.com/docs/business-sdk/getting-started Create a `composer.json` file with the specified content to define your PHP project and require the PHP Business SDK. Replace placeholders with your project details. ```json { "name": "name/{project-name}", "type": "project", "require": { "facebook/php-business-sdk": "^8.0.3" }, "authors": [ { "name": "{Your Name}", "email": "{your@email.com}" } ] } ``` -------------------------------- ### Add Maven Dependency for Java SDK Source: https://developers.facebook.com/docs/business-sdk/getting-started Add this XML code to the `dependency` section of your `pom.xml` file to include the Java Business SDK. ```xml com.facebook.business.sdk facebook-java-business-sdk [8.0.3,) ``` -------------------------------- ### Create Click to Messenger Ad Source: https://developers.facebook.com/docs/business-sdk/common-scenarios/ads-buying Creates an ad campaign designed to run during a specific time period, initiating a Messenger conversation upon click. ```javascript require('dotenv').config(); const business_sdk = require('facebook-nodejs-business-sdk'); const AdAccount = business_sdk.AdAccount; const Ad = business_sdk.Ad; const access_token = process.env.ACCESS_TOKEN; const ad_account_id = process.env.AD_ACCOUNT_ID; const adAccount = new AdAccount(ad_account_id); const ads = adAccount.createAd([ 'name', 'adset_id', 'creative', 'status', 'preview_url' ], { 'name': 'Sample Click to Messenger Ad', 'adset_id': 'act_YOUR_AD_SET_ID', 'creative': { 'name': 'Sample Creative', 'object_story_spec': { 'page_id': 'YOUR_PAGE_ID', 'instagram_actor_id': 'YOUR_INSTAGRAM_ACTOR_ID', 'link_data': { 'call_to_action': { 'type': 'messenger_send_message', 'message': { 'attachment': { 'type': 'template', 'payload': { 'template_type': 'generic', 'elements': [ { 'title': 'Welcome to our page!', 'image_url': 'YOUR_IMAGE_URL', 'subtitle': 'Click the button below to start a conversation.', 'buttons': [ { 'type': 'web_url', 'url': 'YOUR_WEBSITE_URL', 'title': 'Visit Our Website' }, { 'type': 'postback', 'title': 'Send Message', 'payload': 'USER_DEFINED_PAYLOAD' } ] } ] } } } } } } }, 'status': Ad.Status.PAUSED, 'preview_url': true }); ads.then((result) => { console.log(result); }).catch((error) => { console.error(error); }); ``` -------------------------------- ### Enable Crash Reporting in PHP Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Default code to enable crash reporting in PHP applications using Api::init. ```php Api::init($app_id, $app_secret, $access_token); ``` -------------------------------- ### Exchange User Access Token for Page Access Tokens Source: https://developers.facebook.com/docs/business-sdk/common-scenarios/token-switch Use this code to exchange a User access token for a list of Page access tokens for all Pages managed by the user. Page access tokens are valid for 1 hour. ```javascript GET https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN ``` -------------------------------- ### Enable Crash Reporting in Java Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Default code to enable crash reporting in Java applications using APIContext. ```java APIContext context = new APIContext(ACCESS_TOKEN, APP_SECRET); ``` -------------------------------- ### Enable Crash Reporting in Python Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Default code to enable crash reporting in Python applications using FacebookAdsApi.init with debug=True. ```python FacebookAdsApi.init(access_token=access_token, debug=True) ``` -------------------------------- ### Enable Crash Reporting in Ruby Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Default code to enable crash reporting in Ruby applications using FacebookAds.configure. ```ruby FacebookAds.configure do |config| config.access_token = '' config.app_secret = '' end ``` -------------------------------- ### Enable Crash Reporting in JavaScript (Node.JS) Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Default code to enable crash reporting in JavaScript (Node.JS) applications using FacebookAdsApi.init. ```javascript FacebookAdsApi.init(accessToken) ``` -------------------------------- ### Disable Crash Reporting in Java (Alternative) Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Alternative code to disable crash reporting in Java applications by setting a false parameter in APIContext. ```java APIContext context = new APIContext(ACCESS_TOKEN, APP_SECRET, APP_ID, false); ``` -------------------------------- ### Disable Crash Reporting in PHP Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Code to disable crash reporting in PHP applications by setting false as the fourth parameter in Api::init. ```php Api::init($app_id, $app_secret, $access_token, false); ``` -------------------------------- ### Disable Crash Reporting in Python Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Code to disable crash reporting in Python applications by setting crash_log=False in FacebookAdsApi.init. ```python FacebookAdsApi.init(access_token=access_token, debug=True, crash_log=False) ``` -------------------------------- ### Comment on Instagram Posts Source: https://developers.facebook.com/docs/business-sdk/common-scenarios/instagram-management Reply to comments on Instagram posts using the Meta Business SDK. This involves fetching comments and then using their IDs to post replies. ```text POST graph.facebook.com/v18.0/{media-id}/comments message= ``` -------------------------------- ### Disable Crash Reporting in JavaScript (Node.JS) Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Code to disable crash reporting in JavaScript (Node.JS) applications by setting crash_log=false in FacebookAdsApi.init. ```javascript FacebookAdsApi.init(accessToken, crash_log=false) ``` -------------------------------- ### Disable Crash Reporting in Ruby Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Code to disable crash reporting in Ruby applications by setting config.crash_logging_enabled = false in FacebookAds.configure. ```ruby FacebookAds.configure do |config| config.access_token = '' config.app_secret = ''< config.crash_logging_enabled = false end ``` -------------------------------- ### Disable Crash Reporting in Java Source: https://developers.facebook.com/docs/business-sdk/guides/crash-reports Code to disable crash reporting in Java applications by calling APIContext.disableCrashReport(). ```java APIContext context = new APIContext(ACCESS_TOKEN, APP_SECRET); APIContext.disableCrashReport(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.