Skip to content

Integration linkedin 2 apis#222

Closed
fak111 wants to merge 3 commits intomainfrom
integration_linkedin
Closed

Integration linkedin 2 apis#222
fak111 wants to merge 3 commits intomainfrom
integration_linkedin

Conversation

@fak111
Copy link
Contributor

@fak111 fak111 commented Apr 17, 2025

Overview

This integration implements LinkedIn API endpoints into our application, enabling users to access LinkedIn profile information and create social media posts. The integration supports authentication via OAuth 2.0 with the required w_member_social scope for posting functionality.

Application URL: https://api.linkedin.com
API Documentation URL:
1.https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2?context=linkedin%2Fconsumer%2Fcontext

2.https://learn.microsoft.com/zh-cn/linkedin/consumer/integrations/self-serve/share-on-linkedin#creating-a-share-on-linkedin

Integrated API

LINKEDIN__GET_USER_INFO
LINKEDIN__CREATE_SHARE

OAuth Integration Fix

This PR also includes a critical fix to the OAuth authorization process. The oauth2.py file was modified to ensure the w_member_social scope is properly included in the authorization URL, which is essential for the posting functionality to work correctly.

Fuzzy Tests

docker compose exec runner python -m aipolabs.cli.aipolabs fuzzy-test-function-execution \
  --function-name LINKEDIN__GET_USER_INFO \
  --linked-account-owner-id zhuliderb@gmail.com \
  --aipolabs-api-key 206b6f322eb19f1fd9c100237d82e24a121fa979d93ed24cd77b73e190465086 \
  --prompt "获取我的LinkedIn用户信息"


docker compose exec runner python -m aipolabs.cli.aipolabs fuzzy-test-function-execution --function-name LINKEDIN__CREATE_SHARE --linked-account-owner-id zhuliderb@gmail.com --aipolabs-api-key 206b6f322eb19f1fd9c100237d82e24a121fa979d93ed24cd77b73e190465086 --prompt "分享 一个URL到LinkedIn。内容:你看我是谁,我就是个测试这是一个测试分享章。媒体类型:ARTICLE。URL:https://www.linkedin.com。文章标题:测试分享文章。文章描述:你看我是谁,我就是个测试。作者ID:urn:li:person:yfL_d4eZT-"

Images

image
image

Logo

https://raw.githubusercontent.com/aipotheosis-labs/aipolabs-icons/refs/heads/main/apps/linkedin.svg

Summary by CodeRabbit

  • New Features
    • Added LinkedIn integration, enabling users to connect their LinkedIn accounts via OAuth2.
    • Users can now retrieve their LinkedIn profile information and create LinkedIn posts directly from the platform.
  • Bug Fixes
    • Improved handling of LinkedIn-specific OAuth2 authentication flows for a smoother connection experience.
  • Documentation
    • Added detailed configuration and usage information for LinkedIn integration, including supported API functions and required parameters.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 17, 2025

Walkthrough

The changes introduce LinkedIn-specific OAuth2 integration into the system. The OAuth2 wrapper is extended to handle LinkedIn's requirements for client registration, token exchange, token parsing, and authorization URL rewriting. A new asynchronous function is added for LinkedIn's token exchange process, and LinkedIn-specific logic is included in several existing functions. Additionally, new configuration and function definition files are added for LinkedIn, specifying metadata, OAuth2 security scheme, and REST API endpoints for user info retrieval and creating share posts.

Changes

File(s) Change Summary
aipolabs/server/oauth2.py Extended OAuth2 logic with LinkedIn-specific handling: sets token_endpoint_auth_method for LinkedIn, adds LinkedIn code-for-token exchange via HTTP POST, parses LinkedIn token responses, and rewrites authorization URLs for LinkedIn. Introduces new async function linkedin_exchange_code_for_token.
apps/linkedin/app.json Added a new configuration file defining LinkedIn app metadata, OAuth2 security scheme, default credentials, categories, and visibility settings.
apps/linkedin/functions.json Added LinkedIn REST API function definitions: LINKEDIN__GET_USER_INFO (GET user info) and LINKEDIN__CREATE_SHARE (POST share creation), with detailed parameter schemas and required headers.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant OAuth2 Wrapper
    participant LinkedIn API

    Client->>OAuth2 Wrapper: Initiate OAuth2 flow (LinkedIn)
    OAuth2 Wrapper->>OAuth2 Wrapper: create_oauth2_client (LinkedIn logic)
    Client->>OAuth2 Wrapper: Provide authorization code
    OAuth2 Wrapper->>OAuth2 Wrapper: Detect LinkedIn client
    OAuth2 Wrapper->>LinkedIn API: linkedin_exchange_code_for_token (POST /token)
    LinkedIn API-->>OAuth2 Wrapper: Token response
    OAuth2 Wrapper->>Client: Return access token and credentials
Loading

Possibly related PRs

Poem

Oh LinkedIn, you join the hop,
OAuth2 flows, no need to stop!
Tokens exchanged with careful care,
Sharing posts and profiles—rabbits everywhere!
With configs set and endpoints new,
The warren’s network simply grew.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c25e4e and 6fc2649.

📒 Files selected for processing (3)
  • aipolabs/server/oauth2.py (6 hunks)
  • apps/linkedin/app.json (1 hunks)
  • apps/linkedin/functions.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

ACI Integration Code Review (Sonnet 3.7) - 2025-04-17 14:50:47.039

This review analyzes changes to integration files in the app/ directories.

Code Review: LinkedIn Integration

File: apps/linkedin/functions.json

Issue 1: Server URL Format

Line 16-17:

"path": "/userinfo",
"server_url": "https://api.linkedin.com/v2"

Problem: The version number is included in the server_url field, but the path should be adjusted to match the OpenID Connect endpoint.

Suggested Solution: According to the LinkedIn documentation, the OpenID Connect userinfo endpoint should be accessed at https://api.linkedin.com/v2/userinfo. The path should be empty or adjusted accordingly.

"path": "",
"server_url": "https://api.linkedin.com/v2/userinfo"

Issue 2: Visibility Configuration for Headers

Line 35:

"visible": [],

Problem: The visible field for headers is empty, which is correct for hiding implementation details from the LLM, but it should be consistent with the approach used in the rest of the file.

Suggested Solution: This is actually correct as we don't want to expose headers to the LLM, but ensure this approach is consistent throughout the file.

Issue 3: Required vs Visible Fields in GET_USER_INFO

Line 39-40:

"required": [
    "header"
],
"visible": [],

Problem: The visible array is empty for the top-level parameters, which means no parameters will be shown to the LLM. This might make it difficult for the LLM to understand how to use this function.

Suggested Solution: Since this is a simple GET request with no query parameters, this is acceptable, but consider adding a note in the function description that this is a simple authentication check with no required input parameters.

Issue 4: X-Restli-Protocol-Version Header Visibility

Line 83-84:

"visible": [],
"additionalProperties": false

Problem: The X-Restli-Protocol-Version header is correctly marked as required but is not visible to the LLM. According to the special rules, version information should not be shown to the LLM.

Suggested Solution: This is actually correct as we don't want to expose version-related headers to the LLM.

Issue 5: Author Field Requirements

Line 91-94:

"author": {
    "type": "string",
    "description": "Person URN of the member creating the share (retrieved from GET /v2/userinfo)"
}

Problem: The description mentions that the author URN is retrieved from the /v2/userinfo endpoint, but doesn't provide clear guidance on how to format this value.

Suggested Solution: Enhance the description to provide more specific guidance:

"description": "Person URN of the member creating the share in format 'urn:li:person:{id}' where id is retrieved from GET /v2/userinfo"

Issue 6: Media Field Conditional Requirements

Line 136-193:

"media": {
    "type": "array",
    "description": "Media assets attached to the share (required if shareMediaCategory is not NONE)",
    ...
}

Problem: The media field is described as required if shareMediaCategory is not NONE, but this conditional requirement is not enforced in the schema.

Suggested Solution: This is a limitation of the JSON Schema format. Consider adding more explicit information in the description:

"description": "Media assets attached to the share (REQUIRED if shareMediaCategory is ARTICLE or IMAGE, must NOT be provided if shareMediaCategory is NONE)"

Issue 7: Conditional Field Requirements for Media Items

Line 149-193:

"originalUrl": {
    "type": "string",
    "description": "URL of the article to share (required if shareMediaCategory is ARTICLE)"
},
"media": {
    "type": "string",
    "description": "Digital media asset URN (required if shareMediaCategory is IMAGE)"
},

Problem: The conditional requirements for originalUrl and media fields are mentioned in the descriptions but not enforced in the schema.

Suggested Solution: This is a limitation of the JSON Schema format. The descriptions are clear, but consider adding examples in the function description to show how to use these fields correctly.

Summary of Changes and Impact

This PR introduces LinkedIn API integration with two main functions:

  1. LINKEDIN__GET_USER_INFO - Retrieves authenticated user information
  2. LINKEDIN__CREATE_SHARE - Creates posts on LinkedIn with text, URLs, or images

The integration uses OAuth 2.0 authentication with appropriate scopes for accessing profile information and creating social media posts. The implementation follows LinkedIn's API requirements, including necessary headers and data structures.

Impact on Integration Functionality

  • The integration enables users to authenticate with LinkedIn and post content to their profiles
  • The OAuth configuration includes the necessary w_member_social scope for posting functionality
  • The API endpoints are properly configured with the required headers and data structures

Overall Assessment Rating

Acceptable - The integration is functional and follows most best practices, but there are some minor issues with the server URL configuration and conditional field requirements that could be improved.

Actionable Next Steps

  1. Review and adjust the server URL configuration for the LINKEDIN__GET_USER_INFO function
  2. Enhance field descriptions to provide clearer guidance on conditional requirements
  3. Consider adding examples in function descriptions to demonstrate proper usage
  4. Ensure consistent approach to visibility configuration throughout the file
  5. Add more detailed information about how to format the author URN field

The integration is well-structured overall and should provide a solid foundation for LinkedIn functionality in the application.

@github-actions
Copy link

ACI Integration Code Review (Sonnet 3.7) - 2025-04-17 14:51:54.244

This review analyzes changes to integration files in the app/ directories.

LinkedIn Integration Code Review

Issues and Recommendations

1. File: apps/linkedin/functions.json - LINKEDIN__GET_USER_INFO function

Issue: The visible field for the header parameter is empty, but Content-Type should not be exposed to the LLM.
Line: ~33-35
Description: The visible array is empty, which is correct since we don't want to expose Content-Type to the LLM, but this should be explicitly documented.
Suggestion: Keep the empty visible array as is, but consider adding a comment in the code or documentation to clarify this is intentional.

2. File: apps/linkedin/functions.json - LINKEDIN__GET_USER_INFO function

Issue: The visible array at the top level parameters is empty.
Line: ~40-41
Description: The top-level visible array is empty, which means no parameters will be shown to the LLM. This is inconsistent with the function's purpose.
Suggestion: Since this function doesn't require any input from the user, the empty visible array is appropriate. No change needed.

3. File: apps/linkedin/functions.json - LINKEDIN__CREATE_SHARE function

Issue: X-Restli-Protocol-Version header is included but not marked as required.
Line: ~74-79
Description: The LinkedIn API documentation typically requires the X-Restli-Protocol-Version header for API calls, but it's not marked as required in the function specification.
Suggestion: Add "X-Restli-Protocol-Version" to the required array:

"required": [
    "Content-Type",
    "X-Restli-Protocol-Version"
],

4. File: apps/linkedin/functions.json - LINKEDIN__CREATE_SHARE function

Issue: The author field requires a URN but lacks clear formatting guidance.
Line: ~90-94
Description: The author field requires a LinkedIn URN format (e.g., "urn:li:person:12345"), but the description doesn't provide clear guidance on the format.
Suggestion: Enhance the description to include the expected format:

"description": "Person URN of the member creating the share in format 'urn:li:person:{id}' (retrieved from GET /v2/userinfo)"

5. File: apps/linkedin/functions.json - LINKEDIN__CREATE_SHARE function

Issue: Conditional requirements for media array are not enforced in the schema.
Line: ~134-196
Description: The media array is required when shareMediaCategory is not "NONE", but this conditional requirement is not enforced in the schema.
Suggestion: Add a note in the description to make this clearer:

"description": "Media assets attached to the share (REQUIRED if shareMediaCategory is ARTICLE or IMAGE, should not be included if NONE)"

6. File: apps/linkedin/functions.json - Server URL format

Issue: The server URL includes the version number in both functions.
Line: ~16 and ~59
Description: According to the special rules, the version number should be in the server_url field, not in the path field, which is correctly implemented.
Suggestion: No change needed, this is correctly implemented.

Summary of Changes and Impact

This PR introduces LinkedIn API integration with two key functions:

  1. LINKEDIN__GET_USER_INFO - Retrieves authenticated user details using OpenID Connect
  2. LINKEDIN__CREATE_SHARE - Creates posts on LinkedIn with support for text, URLs, and images

The integration is well-structured and follows most best practices for API integration. The OAuth2 configuration is properly set up with the required scopes, including the critical w_member_social scope needed for posting functionality.

The function specifications are generally well-defined with appropriate parameters, descriptions, and visibility settings. The implementation correctly separates the API version into the server URL and follows the required naming conventions.

Impact on Integration Functionality

The integration provides essential LinkedIn functionality that allows users to:

  • Authenticate with LinkedIn via OAuth2
  • Retrieve their profile information
  • Create posts with various media types (text-only, articles, images)
  • Control the visibility of their posts

These capabilities enable a robust LinkedIn integration that covers the core use cases for most applications.

Overall Assessment

Rating: Acceptable

The LinkedIn integration is well-implemented with proper OAuth configuration and comprehensive function specifications. The issues identified are minor and don't significantly impact the functionality of the integration.

Actionable Next Steps

  1. Add X-Restli-Protocol-Version to the required headers for the CREATE_SHARE function
  2. Enhance the description of the author field to include the expected URN format
  3. Clarify the conditional requirements for the media array in the CREATE_SHARE function
  4. Consider adding more detailed error handling guidance in the function descriptions
  5. Consider adding additional LinkedIn API endpoints in future PRs to expand functionality (e.g., commenting, connection management)

The integration is ready for use after addressing these minor issues, particularly the required header for the CREATE_SHARE function.

@thisisfixer
Copy link
Contributor

thisisfixer commented Apr 17, 2025

closing this for now.
need further evaluation.
we can skip linkedin integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants