Authenticating to Facebook
Facebook uses the OAuth standard to authenticate users.
Authenticate via OAuth Authentication
See Using OAuth Authentication for an authentication guide.
Posting as a Page
After authenticating to Facebook with your user account, you can post, etc. as one of the pages you manage: Set the AuthenticateAsPage property to the Id of the page you want. You can find the Ids for all pages your account has access to by querying the Pages view.
Automatic Page Authentication
Facebook has made a number of recent changes that require page tokens for most resources owned by a page. This can be troublesome if you manage multiple pages and want to execute the same queries across all pages (such as retrieving Insights). In order to make this work seamlessly with our tools, we have added a way to automatically detect the page token to use. For this to work, simply do not specify the AuthenticateAsPage. Note that the correct page token can only be resolved if the page id is specified as part of the target in the request. This means for some requests you will still need to manually specify AuthenticateAsPage.
Requesting Additional Permissions
You may find while using the provider that Facebook returns an error stating your app does not have permissions to do a certain action. To resolve this, you will need to generate a new OAuth access token with the required permissions. Set the Permissions property in the authentication step for a desktop application.
Web applications need to call the GetOAuthAuthorizationURL and GetOAuthAccessToken stored procedures, which have inputs for the permissions you would like to request.
Note that these are comma-separated lists of permissions, so you can request more than one per authorization request.
You can find a list of available Facebook permissions here: http://developers.facebook.com/docs/authentication/permissions/.
Fine-Tuning Data Access
- Target: Some Facebook tables can be filtered by a target. For example, to retrieve comments on a video, specify the Id of the video as the target. This property enables you to restrict the results of all queries in the connection to records that match the specified target. You can also specify this restriction per query with the Target column.
- AggregateFormat: The provider returns some columns as a string aggregate. For example, the available likes data for an entity is returned in aggregate. By default, the provider returns aggregate columns in JSON. You can also return aggregates in XML.
- Version: Set this property to the Facebook API version if you need to work with a different version than the default.
Using OAuth Authentication
OAuth requires the authenticating user to interact with Facebook using the browser. The provider facilitates this in various ways as described below.
Embedded Credentials
See Embedded Credentials to connect with the provider's embedded credentials and skip creating a custom OAuth app.Custom Credentials
When to Create a Custom OAuth App
You need to create a custom OAuth app in the web flow.
Desktop Applications
Creating a custom OAuth app is optional as the provider is already registered with Facebook and you can connect with its embedded credentials. Create a custom OAuth app in the following scenarios:
- If you need to request additional permissions over the provider defaults.
- If you want to change the information displayed when users log into the Facebook OAuth endpoint to grant permissions to the provider.
Creating a Custom OAuth App
See Creating a Custom OAuth App for a procedure.
Embedded Credentials
Authenticate using the Embedded OAuth Credentials
Desktop Authentication with the Embedded OAuth App
You can connect without setting any connection properties for your user credentials. After setting InitiateOAuth to GETANDREFRESH you are ready to connect. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken. Optionally, set AuthenticateAsPage to the name or Id of a page you manage to make requests as a page.
When you connect the provider opens the OAuth endpoint in your default browser. Log in and grant permissions to the application. The provider then completes the OAuth process.
- Extracts the access token from the callback URL and authenticates requests.
- Obtains a new access token when the old one expires.
- Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
Custom Credentials
Desktop Authentication with a Custom OAuth App
Follow the steps below to authenticate with the credentials for a custom OAuth app. See Creating a Custom OAuth App.After setting the following, you are ready to connect:
- OAuthClientId: Set this to the App Id in your app settings.
- OAuthClientSecret: Set this to the App Secret in your app settings.
- CallbackURL: Set this to the Site URL in your app settings.
- InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
- Permissions (optional): Set this if you need to customizie the permissions that the provider requests.
- AuthenticateAsPage (optional): Set this to a page name or Id to make requests as a page. The page must be managed by the authenticated user.
- Extracts the access token from the callback URL and authenticates requests.
- Obtains a new access token when the old one expires.
- Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
Web Authentication with a Custom OAuth App
When connecting via a Web application, you need to register a custom OAuth app with Facebook. See Creating a Custom OAuth App. You can then use the provider to get and manage the OAuth token values.
Get an OAuth 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.
- Permissions (optional): Set this if you need to customizie the permissions that the provider requests.
- AuthenticateAsPage (optional): Set this to a page name or Id to make requests as a page. The page must be managed by the authenticated user.
You can then call stored procedures to complete the OAuth exchange:
-
Call the GetOAuthAuthorizationURL stored procedure. Set the AuthMode input to WEB and set the CallbackURL input to the Redirect URI you specified in your app settings. If necessary, set the Permissions parameter to request custom permissions.
The stored procedure returns the URL to the OAuth endpoint.
- Open the URL, log in, and authorize the application. You are redirected back to the callback URL.
- Call the GetOAuthAccessToken stored procedure. Set the AuthMode input to WEB. Set the Verifier input to the "code" parameter in the query string of the callback URL. If necessary, set the Permissions parameter to request custom permissions.
To connect to data, set the OAuthAccessToken connection property to the access token returned by the stored procedure. When the access token expires after ExpiresIn seconds, call GetOAuthAccessToken again to obtain a new access token.
Requesting Additional Permissions
You may find while using the provider that Facebook returns an error stating your app does not have permissions to do a certain action. To resolve this, you will need to generate a new OAuth access token with the required permissions. Set the Permissions property in the authentication step for a desktop application.
Web applications need to call the GetOAuthAuthorizationURL and GetOAuthAccessToken stored procedures, which have inputs for the permissions you would like to request.
Note that these are comma-separated lists of permissions, so you can request more than one per authorization request. You can find a list of available Facebook permissions here: http://developers.facebook.com/docs/authentication/permissions/.
Creating a Custom OAuth App
Create a Custom OAuth App: Desktop
To obtain the OAuth client credentials, follow the steps below:
- Log into Facebook and navigate to https://developers.facebook.com/apps.
- Create a new app and click Settings > Basic. The OAuthClientId is the App Id displayed. The OAuthClientSecret is the App Secret.
- Add a website platform on the Settings tab. Enter a Site URL. This value is not used in authentication.
Follow the steps below to configure the OAuth redirect URI.
- Go to your app settings and add the Facebook Login product from the Products section.
- In the product settings, define the OAuth redirect URI.
Set the redirect URI to https://localhost:33333/, or some other similar https url.
Create a Custom OAuth App: Web Apps
To obtain the OAuth client credentials, follow the steps below:
- Log into Facebook and navigate to https://developers.facebook.com/apps.
- Create a new app and click Settings > Basic. The OAuthClientId is the App Id displayed. The OAuthClientSecret is the App Secret.
- Add a website platform on the Settings tab. Enter a Site URL. This value is not used in authentication.
Follow the steps below to configure the OAuth redirect URI.
- Go to your app settings and add the Facebook Login product from the Products section.
- In the product settings, define the OAuth redirect URI.
Set the redirect URI you want to be used as a callback URL, where the user will return with the token that verifies that they have granted your app access.
Customizing the SSL Configuration
By default, the provider attempts to negotiate SSL/TLS by checking the server's certificate against the system's trusted certificate store. To specify another certificate, see the SSLServerCert property for the available formats to do so.
Connecting Through a Firewall or Proxy
HTTP Proxies
To connect through the Windows system proxy, you do not need to set any additional connection properties. To connect to other proxies, set ProxyAutoDetect to false.
In addition, to authenticate to an HTTP proxy, set ProxyAuthScheme, ProxyUser, and ProxyPassword, in addition to ProxyServer and ProxyPort.
Other Proxies
Set the following properties:
- To use a proxy-based firewall, set FirewallType, FirewallServer, and FirewallPort.
- To tunnel the connection, set FirewallType to TUNNEL.
- To authenticate, specify FirewallUser and FirewallPassword.
- To authenticate to a SOCKS proxy, additionally set FirewallType to SOCKS5.
Troubleshooting the Connection
To show provider activity from query execution to network traffic, use Logfile and Verbosity. The examples of common connection errors below show how to use these properties to get more context. Contact the support team for help tracing the source of an error or circumventing a performance issue.
- Authentication errors: Typically, recording a Logfile at Verbosity 4 is necessary to get full details on an authentication error.
- Queries time out: A server that takes too long to respond will exceed the provider's client-side timeout. Often, setting the Timeout property to a higher value will avoid a connection error. Another option is to disable the timeout by setting the property to 0. Setting Verbosity to 2 will show where the time is being spent.
- The certificate presented by the server cannot be validated: This error indicates that the provider cannot validate the server's certificate through the chain of trust. If you are using a self-signed certificate, there is only one certificate in the chain.
To resolve this error, you must verify yourself that the certificate can be trusted and specify to the provider that you trust the certificate. One way you can specify that you trust a certificate is to add the certificate to the trusted system store; another is to set SSLServerCert.