Get User ID Using Facebook API

By
 import logging
from fastapi import FastAPI
from starlette.responses import RedirectResponse
from facebook_user_id_fetcher import router as facebook_user_id_router

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.WARNING)

app = FastAPI()

app.include_router(facebook_user_id_router)

@app.get("/", include_in_schema=False)
def root():
    return RedirectResponse(url='/docs')

# Do not remove the main function while updating the app.
if __name__ == "__main__":
    import uvicorn

    # This initialization is essential and must not be removed.
    uvicorn.run(app, host="0.0.0.0", port=8080, log_level="info")

About this template

An app that retrieves the Facebook user ID using the Facebook API. No specific permissions are required to make this api call. This app uses the FastAPI to create an endpoint to call the Facebook API for getting a logged-in user's id. A facebook access token will be needed to make the API call.

Introduction to the Get User ID Using Facebook API Template

Welcome to the "Get User ID Using Facebook API" template guide. This template is designed to help you quickly set up an application that retrieves a Facebook user ID using the Facebook API. It leverages FastAPI to create an endpoint that interacts with the Facebook API, requiring only a Facebook access token to make the call. This guide will walk you through the steps to use this template on the Lazy platform, ensuring you can deploy and integrate the application with ease.

Clicking Start with this Template

To begin using this template, simply click on the "Start with this Template" button. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code manually.

Test: Pressing the Test Button

Once you have started with the template, the next step is to press the "Test" button. This will initiate the deployment of your application and launch the Lazy CLI. The deployment process is handled entirely by Lazy, so you don't need to worry about installing libraries or setting up your environment.

Entering Input: Filling in User Input

After pressing the "Test" button, if the application requires user input, the Lazy App's CLI interface will prompt you to provide it. For this template, you will need to enter a valid Facebook access token. To obtain an access token, you must create a Facebook app and go through the Facebook authentication flow. Detailed instructions on how to do this can be found in the Facebook Developer documentation:

  • Visit the Facebook Developer portal and create a new app.
  • Configure the app's settings to obtain the necessary permissions.
  • Use the Graph API Explorer or implement the Facebook login flow to get an access token.

Once you have the access token, enter it into the CLI when prompted.

Using the App

After the application is deployed, Lazy will provide you with a dedicated server link to use the API. Additionally, since this template uses FastAPI, you will also be provided with a link to the API documentation. You can use these links to interact with the API and retrieve Facebook user IDs.

Integrating the App

If you need to integrate this application into an external service or frontend, you can use the server link provided by Lazy. For example, you can make a GET request to the `/get-user-id` endpoint with the access token as a query parameter to fetch the user ID. Here's a sample request you might use:


GET /get-user-id?access_token=YOUR_FACEBOOK_ACCESS_TOKEN

And here's a sample response you can expect:


{
  "id": "1234567890123456"
}

If you need to integrate this endpoint into another tool, you can add the provided server link as an API endpoint in that tool. Make sure to follow the specific instructions for the external tool to add the API endpoint correctly.

By following these steps, you should now have a fully functional application that can retrieve Facebook user IDs using the Facebook API, all set up and running on the Lazy platform.

Category
Technology
Last published
April 7, 2024

More templates like this

Customisable Server Status Dashboard

This template allows you to create a dashboard to report about incidents regarding your server to your users.

Streamlit
Python

A bot that answers questions about data

Ask questions about your database via a chat bot. This chatbot connects to a SQLITE database, generates queries for it based on the schema and then runs the queries printing the response all in a nicely styled chat UI. This template is pre-loaded with sample data (car parts) to play around with - here are the sample data columns that you can query: part_number, part_name, price, units_left_in_stock, manufacturer .

Python
Flask

WhatsApp Bot Builder

The WhatsApp Bot Builder app allows users to create a WhatsApp bot that responds to every message with "Hello World".

WhatsApp
Twilio
Python
Home
/
Get User ID Using Facebook API