CData Python Connector for Instagram

Build 23.0.8868

Creating a Custom OAuth App

When to Create a Custom OAuth App

CData embeds OAuth Application Credentials with CData branding that can be used when connecting via a desktop application or headless application. Web applications require a custom OAuth application. You may choose to use your own OAuth Application Credentials when you want to
  • control branding of the Authentication Dialog
  • control the redirect URI that the application redirects the user to after the user authenticates
  • customize the permissions that you are requesting from the user

Allow Access to Instagram Data

To allow users to connect through the connector, complete the tasks below:

  1. Connect a Facebook Page to an Instagram account.
  2. Create and register the connector as an app with Instagram.
  3. Submit your app for Facebook's review.

Connect a Facebook Page to an Instagram Account

To access Instagram data, users need a role on a page that is associated with an Instagram account. Any user with a role on the page has access.

To connect a page and an Instagram account, log into Facebook and from your Page's settings, click Instagram, and log into your Instagram account. If your account is not an Instagram Business Account, follow the prompts to set up a business profile.

Create and Register the App

Register an app to obtain the values for the OAuthClientId and OAuthClientSecret properties. The OAuth client credentials authenticate the connector to Facebook.

  1. Log into Facebook and navigate to https://developers.facebook.com/apps.
  2. Create a new app and click Settings > Basic. The OAuthClientId is the App Id displayed. The OAuthClientSecret is the App Secret.
  3. Click Add Platform and select Website. Enter a Site URL. This value is not used in authentication.
Add the Facebook Login Product

Follow these steps to configure the OAuth redirect URI.

  1. Go to your app settings and add the Facebook Login product from the "Products" section.
  2. In the product settings, define the OAuth redirect URI.

    If you are building a desktop application, set the redirect URI to https://localhost:33333/, or a similar https url.

    If you are building a web application, set the redirect URI you want to be used as the callback URL that users return to with the token that verifies that they have granted your app access.

Add the Instagram API Product

Follow these steps to configure the Instagram API permissions your app requests:

  1. Go to your app settings and add the Instagram product from the "Products" section.
  2. Configure the permissions in the product settings. To access all the tables and views, include the following scopes:
    • instagram_basic
    • instagram_manage_comments
    • instagram_manage_insights

    See the Data Model section for detailed information about the scopes required for specific tables.

Submit the App for Review to Go Live

While you can still with an application without review, to go live and fully access Instagram content, you must submit your application for review and approval.

  1. Click Manage for your application and on the Permissions tab click Start a Submission.
  2. Select the use case that best describes your Instagram integration.
  3. Fill in the form and wait for your application to be approved.

Authenticate to Instagram

Desktop Applications

After setting the following connection properties, you are ready to connect:

  • OAuthClientId: Set this to the App Id for your OAuth app.
  • OAuthClientSecret: Set this to the App Secret for your OAuth app.
  • InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
  • BusinessAccountId: If you have more than one Facebook page connected with an Instagram account, set the BusinessAccountId connection property to specify the Id of a business account you have associated with a Facebook page.

    You can get a business account Id by querying the Page view.

When you connect, the connector opens the OAuth endpoint in your default browser. Log in and grant permissions to the application. The connector then completes the OAuth process:
  1. Extracts the access token from the callback URL and authenticates requests.
  2. Obtains a new access token when the old one expires.
  3. Saves OAuth values in OAuthSettingsLocation. These values persist across connections.

Web Applications

Follow the steps below to use the connector to get the OAuth token values and connect from a web application. Get an Access Token

Set the following connection properties to obtain the OAuthAccessToken:

  • OAuthClientId: Set this to the App Id in your app settings.
  • OAuthClientSecret: Set this to the App Secret in your app settings.

Then follow these steps to complete the OAuth exchange:

  1. Call the GetOAuthAuthorizationURL stored procedure. Set the AuthMode input to WEB and set the CallbackURL input to the OAuth redirect URI you specified in your app settings. The stored procedure returns the URL to the OAuth endpoint.
  2. Log in and authorize the application. You are redirected back to the callback URL.

    The callback URL contains the verifier code in a query string parameter. Extract the verifier code from the callback URL.

  3. Set the following parameters and call GetOAuthAccessToken:

    NameValue
    AuthModeWEB
    VerifierSet this to the verifier code.
    CallbackURLSet this to the callback URL in your app settings.

Connect to Data To make requests to Instagram, set the OAuthAccessToken property. The OAuthAccessToken has a limited lifetime. When the token expires, you need to call the preceding stored procedures to reauthenticate.

Connect to Multiple Pages

If you have more than one Facebook page connected with an Instagram business account, set BusinessAccountId in addition to OAuthAccessToken. The BusinessAccountId property specifies the Id of a business account you have associated with a Facebook page.

You can get a business account Id by querying the Page View.

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8868