Gen AI Developer Classroom Notes – 21/Jul/2025

MCP Server

  • Lets build a mcp server by following best practices and async based for an application which already has a REST API

  • Lets build an mcp server which posts to social media (Linked In, Facebook, instagram )

  • Refer Here for the toml structure

  • As an experiment lets try calling apis to fakestoreapi

  • Refer Here for the notebook with sync and async calling

  • Refer Here for the chagnes done specifically into the post call with execption handling

  • Exercise: Implement fetch in the same way as post with type hinting and exception handling Refer Here for post implementation

Getting linked API Key, Client Id and Client Secret

To enable LinkedIn API access for your account, you need to follow LinkedIn’s official process, which uses OAuth 2.0 for both application authentication and permissions management. Here’s a clear step-by-step guide based on the latest documentation and best practices:

1. Create a LinkedIn Developer Account and Application

  • Go to the LinkedIn Developer portal and sign in with your LinkedIn credentials.
  • Navigate to “My Apps” and select Create App.
  • Fill in required app details such as the application name, business website, logo, OAuth 2.0 Redirect URLs, and business email.
  • You can add a company page if you’re registering the app on behalf of a business[2][5][6].

2. Set Up Application Permissions

  • LinkedIn offers Open Permissions (such as basic profile and email access, or permission to share posts), which are available to all developers and can be enabled through the Products tab in your app settings.
  • More advanced permissions (like full profile, connections, or other restricted data) require explicit approval through LinkedIn’s partner programs. Most individuals or small businesses are limited to the open, self-service permissions[1][6].

3. Obtain API Keys

  • Once your application is set up, LinkedIn will generate a Client ID and Client Secret. These will be needed to authenticate all API requests and must be kept secure[3][6].

4. Authenticate via OAuth 2.0

  • To request API access on behalf of a user (yourself), you must use OAuth 2.0:
    • For member-specific actions (like reading profile data or posting), use the 3-legged OAuth flow (user authorization).
    • For application-only features, use the 2-legged OAuth flow (application authorization)[1][6].

Sample Access Token Retrieval (OAuth 2.0, Application Authentication):

const axios = require('axios');

const getAccessToken = async () => {
  const LI_ACCESS_TOKEN_EXCHANGE_URL = 'https://www.linkedin.com/oauth/v2/accessToken';
  const response = await axios.post(LI_ACCESS_TOKEN_EXCHANGE_URL, null, {
    params: {
      grant_type: 'client_credentials',
      client_id: 'your-client-id',       // Replace with your actual client ID
      client_secret: 'your-client-secret' // Replace with your actual client secret
    }
  });
  return response.data.access_token;
};

Note: Replace 'your-client-id' and 'your-client-secret' with the credentials from your LinkedIn app[5][6].

5. Make API Requests

  • Use the retrieved access token in the Authorization header for all LinkedIn API calls. For example, to fetch user profile data (if permission is granted):
const getProfile = async (accessToken, profileId) => {
  const LI_PROFILE_API_ENDPOINT = `https://api.linkedin.com/v2/people/${profileId}`;
  const response = await axios.get(LI_PROFILE_API_ENDPOINT, {
    headers: {
      'Authorization': `Bearer ${accessToken}`,
      'X-RestLi-Protocol-Version': '2.0.0'
    }
  });
  return response.data;
};
  • You need the profile ID to retrieve profile data; LinkedIn does not allow access via profile URLs with its official public API[5][6].

Important Considerations:

  • Most API features are locked down. Since 2015, LinkedIn restricts many APIs to vetted partners. Individual users and typical businesses can use only the open/self-service permissions (basic profile, email, and sharing content)[1][6].
  • Keep credentials secure and never expose your client secret publicly[3].
  • Follow LinkedIn’s data and usage policies to avoid your app being restricted or banned[6].

Unofficial APIs: Some third-party services (like ScrapIn) allow profile retrieval via URLs, but these are not endorsed by LinkedIn and may violate terms of service[5].

For most users, you will be able to:

  • Read your own profile (name, photo, headline, email) with Sign In with LinkedIn.
  • Post, comment, and like on LinkedIn via your app with Share on LinkedIn[1].

To do more (like reading connections or detailed profiles), you must apply for partner-level access, which is rarely granted to individuals or small companies[1][6].

[1] https://learn.microsoft.com/en-us/linkedin/shared/authentication/getting-access [2] https://www.linkedin.com/help/linkedin/answer/a526048 [3] https://www.getphyllo.com/post/linkedin-api-ultimate-guide-on-linkedin-api-integration [4] https://learn.microsoft.com/en-us/linkedin/shared/integrations/people/profile-api [5] https://www.scrapin.io/blog/linkedin-api [6] https://www.unipile.com/linkedin-api-a-comprehensive-guide-to-integration/ [7] https://developer.linkedin.com [8] https://stackoverflow.com/questions/60124525/linkedin-api-access [9] https://www.linkedin.com/help/linkedin/answer/a519947/third-party-applications-data-use?lang=en

Facebook

To get Facebook API access, follow these structured steps—which apply to most Facebook/Meta API integrations, including posting, automation, and analytics. These steps are suitable for developers and businesses aiming to interact programmatically with Facebook:

1. Register as a Meta (Facebook) Developer

2. Create a New App

  • In the dashboard, click “My Apps” and then “Create App.”
  • Choose the appropriate app type (e.g., Business or None for most cases).
  • Enter your app name, contact email, and required details[1][2][3][10].

3. Configure App Settings

  • Follow prompts to set up your app’s basic settings.
  • You might need a privacy policy URL for public-facing apps (can be generated with a free tool, if needed)[1].

4. Add Products/Permissions

  • Add the Facebook Login product for user authentication, or configure access to specific resources like Facebook Pages or Instagram[1][3][4].
  • Under the “App Review” section, request the permissions your integration needs (e.g., pages_manage_posts, pages_read_engagement for Page posting or reading data)[4][6].

5. Generate Access Tokens

  • Use the Access Token Tool (Graph API Explorer) to create access tokens with your app and required permissions[2][3][4][8].
  • Choose permissions, generate the token, and keep it secure. Never expose tokens in client-side code[1][2][3][5][10].

Example API Request
To fetch your profile using the Graph API Explorer or other HTTP clients:

GET https://graph.facebook.com/v12.0/me?access_token=YOUR_ACCESS_TOKEN

Replace YOUR_ACCESS_TOKEN with your generated token[2][5].

6. Test and Use API Calls

  • Use the Graph API Explorer for live testing (supports GET, POST, DELETE). You can also get code samples in multiple programming languages[4][8].
  • For posting to a Page:
POST https://graph.facebook.com/{PAGE_ID}/feed
-d "message=Hello, world!"
-d "access_token=YOUR_PAGE_ACCESS_TOKEN"

This publishes ‘Hello, world!’ to the specified Page[5][4].

7. Review Access Levels

  • Most permissions start with Standard Access by default. For broad or sensitive data needs (multiple users, advanced scopes), business verification and App Review are required for “Advanced Access”[3][4].

8. Monitor & Maintain

  • Tokens can expire. Use long-lived tokens for production and monitor usage/rate limits[2].
  • Regularly review permissions and keep your app up to date with API changes[9].

Summary Table: Essential Steps

Step Action
Developer Registration developers.facebook.com > Log in/Create Account
Create App “My Apps” > “Create App” > Fill details
Configure Add Facebook Login/Pages/Instagram; set privacy policy
Permissions/App Review Select permissions; submit for review if needed
Generate Access Token Graph API Explorer or SDK; select permissions
Make API Calls Use token in requests (e.g., to fetch user or post to Page)
Maintain Access Monitor tokens, review limits, update app as needed

References: All steps above are derived strictly from the most up-to-date guides and documentation[1][2][3][4][5][6][7][8][10].

[1] https://www.linkedin.com/pulse/step-by-step-guide-connecting-facebook-meta-graph-api-riaz-ahmad-butt-ouh5f [2] https://moldstud.com/articles/p-step-by-step-tutorial-how-to-use-facebook-api-for-new-developers [3] https://www.youtube.com/watch?v=BuF9g9_QC04 [4] https://developers.facebook.com/docs/pages-api/getting-started/ [5] https://developers.facebook.com/docs/graph-api/overview/ [6] https://developers.facebook.com/docs/graph-api/get-started/ [7] https://developers.facebook.com/docs/graph-api/ [8] https://developers.facebook.com/docs/graph-api/guides/explorer/ [9] https://developers.facebook.com/blog/post/2025/01/21/introducing-graph-api-v22-and-marketing-api-v22/ [10] https://elfsight.com/blog/how-to-get-and-use-facebook-api/

Instagram

To get Instagram API access in 2025, you’ll use Meta’s official platform. The exact flow depends on whether you’re accessing basic profile/media features (via the Basic Display API) or managing a business/creator account (via the Graph API). Requirements and steps are as follows:

Core Requirements

  • Meta (Facebook) Developer Account
  • Instagram Business or Creator Account
  • Facebook Page (for Business/Creator accounts, as it must be linked)
  • Registered App within the Meta (Facebook) Developer portal[1][2][6][9]

Step-by-Step Procedure

1. Create a Meta Developer Account & Register Your App

  • Visit Meta for Developers and log in.
  • Go to “My Apps,” click Create App, and follow the prompts to register your app.
  • Choose the app type (usually “Business” or “Other”) and fill in all required fields (name, contact details)[1][4].

2. Add the Instagram Product

  • In your app dashboard, navigate to the sidebar and click Add Product, then select Instagram (typically “Instagram Graph API” or “Instagram Basic Display” based on your needs)[1][4][9].
  • For business/creator usage (Graph API), your Instagram account needs to be linked to a Facebook Page you own[2][8][9].

3. Configure Permissions and Settings

  • Set requested permissions:
    • instagram_basic for profile/media
    • pages_show_list, manage_pages for page insights/actions, hashtag search, etc.[2][3]
  • Some permissions (beyond basic) and public deployments require your app to go through App Review by Meta[7].

4. Connect Accounts

  • Under the Instagram settings, link your Business or Creator Account (individual accounts must first be converted)[1][2][6][9].
  • Confirm the Facebook Page link if required.

5. Generate Access Token

  • In the app dashboard’s Instagram section, click Generate Token[1][5].
  • Use standard OAuth 2.0 flows:
    • Send users to the Instagram authorization URL to grant your app requested permissions.
    • Obtain the authorization code and exchange it for a short-lived access token.
    • Optionally, exchange for a long-lived token (recommended for production use)[5].
  • For Graph API: Use the access token in your API requests to fetch posts, media, profile info, search hashtags, etc.[2][5].
  • Example:
    GET https://graph.instagram.com/me?fields=id,username&access_token={access-token}
    

6. Test and Use the API

  • Make authenticated requests to the Instagram API endpoints.
  • Follow rate limits and Meta’s data use guidelines[1].

Key Notes

  • As of December 2024, only the new Instagram APIs are supported—older Basic Display flows are deprecated[4].
  • If connecting third-party SaaS or analytics tools, you’ll typically follow the same OAuth and token workflow using their integration screens.
  • Personal Instagram accounts (not business or creator) have highly limited access—upgrade if you need full feature support[3][5][9].

Common Use Cases

  • Show user media/posts in external apps
  • Automate posting for business/creator pages
  • Analyze engagement, hashtags, and mentions

Always consult the Meta for Developers Instagram docs for up-to-date requirements and permission details[6][7].

Summary Table: Instagram API Requirements

Item Required?
Meta Developer Account Yes
Instagram Business/Creator Yes (for Graph API)
Facebook Page Yes (linked to business/creator IG)
App Registration Yes
App Review Sometimes (for advanced permissions)

In summary: Register as a Meta developer, create your app, add the Instagram API, connect your business/creator IG (linked to a Facebook Page), set permissions, and generate your access token to start making requests[1][2][5][9].

[1] https://taggbox.com/blog/instagram-api/ [2] https://www.getphyllo.com/post/instagram-graph-apis-what-are-they-and-how-do-developers-access-them [3] https://www.insightiq.ai/blog/instagram-public-content-access-developers [4] https://docs.uxthemes.com/article/433-instagram-api-token [5] https://www.getphyllo.com/post/how-to-use-instagram-basic-display-api [6] https://developers.facebook.com/docs/instagram-platform/ [7] https://developers.facebook.com/docs/instagram-platform/overview/ [8] https://www.postman.com/meta/instagram/documentation/6yqw8pt/instagram-api [9] https://www.unipile.com/instagram-api-integration-the-complete-developers-guide-for-software-editors/

Twitter (X)

How to Get API Access on X (formerly Twitter)

Here’s a practical guide to obtaining and using X API access as of July 2025:

Core Steps

1. Sign Up for a Developer Account

  • Visit the X Developer Platform (developer.x.com) and sign in with your X account.
  • Apply for a developer profile, describing your intended use case (e.g., posting, analytics, bots). This description must usually be at least 250 characters[1][2].
  • Verify your account via the email sent to you.

2. Choose Your Access Tier

  • Free: Suitable for basic, write-only and test use. Allows 500 posts and 100 reads per month, with single app and project[3][4].
  • Basic: $200/month (or $175/month with annual payment). Allows 10,000 posts/month, with two app environments. Required for most common data-integration use cases[3][4].
  • Pro: $5,000/month (discount for annual). Higher rate limits: 1M posts/month, useful for scaling and analytics[3][4].
  • Enterprise: Custom plans starting at $42,000/month, offering highest throughput and dedicated support[4].

Important: The free tier is quite limited. To ingest (read) content, at least the Basic plan is required[2][4].

3. Create a Project and App

  • After approval, access the X Developer portal and create a Project, then an App under that project.
  • Set up authentication type and callback URLs based on your intended workflow—use OAuth for user-based actions.

4. Generate API Keys and Tokens

  • Each app generates:
    • API Key and Secret
    • Access Token and Secret
  • Store these securely. You’ll use them to sign requests and authenticate API calls[1][2][5].

5. Configure App Permissions

  • Select the necessary permissions: read, write, and/or direct messages, based on your plan and use case.
  • To post or fetch data via your bots or integrations, configure your app as a “Web App, Automated App or Bot” and allow the corresponding scopes[2].

6. Make API Requests

  • For authentication, follow the OAuth 2.0 workflow.

  • Example: To post data (requires write permission):

    POST https://api.x.com/2/tweets
    Headers: Authorization: Bearer YOUR_ACCESS_TOKEN
    
  • Refer to the developer docs for endpoint specifics and rate limits[3][6].

Common Use Cases

  • Posting: Automate publishing to your account or a managed entity.
  • Reading Data: Analyze posts, mentions, and conversations (requires Basic tier or higher).
  • Messaging: Direct Messages and notifications to followers.
  • Analytics: Collect engagement metrics, impressions, etc. (primarily on paid tiers)[3][7].

Summary Table: X API Requirements

Step Action
Developer Account Register at developer.x.com, describe use case[1][2]
Select Access Tier Free, Basic, Pro, or Enterprise[3][4]
Create Project & App Create via Developer Portal[1][5]
Generate API Keys App dashboard > Generate keys/tokens[1][2][5]
Permissions & Review Set app permissions, submit for review if needed[2][5]
Use API OAuth authenticate, make requests[3][6]

Notes and Tips

  • Paid access (Basic, Pro, Enterprise) is required for most content ingestion and analytics features.
  • Changes in X API access and pricing occur frequently—always review the latest terms on the official developer portal[3][4][5].
  • Keep all API credentials private to avoid security risks.
  • If you need higher limits or commercial usage, apply for the appropriate tier directly through the developer portal[3][4].

By following these steps, you can integrate your application or service with X and leverage its data and communication tools programmatically.

[1] https://www.youtube.com/watch?v=c4VYIskH-bQ [2] https://support.tintup.com/hc/en-us/articles/16130285332371-How-to-setup-the-X-API-Key [3] https://developer.x.com/en/docs/x-api [4] https://developer.x.com/en/support/x-api/v2 [5] https://docs.x.com/x-api/getting-started/getting-access [6] https://docs.x.com/x-api/introduction [7] https://www.unipile.com/communication-api/messaging-api/x-api/ [8] https://developer.x.com/en [9] https://developer.twitter.com/en/portal/petition/essential/basic-info [10] https://developer.x.com/en/products/x-api/enterprise/enterprise-api-interest-form

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading