Lens Content APIs

APIs for Content Recommendations

Posts by profiles are scored (value between 0 and 1), classified (recommendable, maybe recommendable, not recommendable) and ranked every hour. The posts can then be retrieved by clients through any of the following 4 APIs.

As an example, the /feed endpoint returns a JSON array of posts using the Popular algorithm as a default algorithm. To choose a different algorithm, specify the algorithm as a path parameter.

Let's walk through all the Global and Personalized content feed recommendation APIs next.

Global Feed

As for generalized (non-personalized) feed of posts according to each algorithm, we now have the following pre-computed algorithms. These algorithms are:

  • /feed/recent to choose the Recent algorithm.

  • /feed/popular to explicitly choose the Popular algorithm.

  • /feed/recommended to choose the Recommended algorithm.

  • /feed/crowdsourced to choose the Crowdsourced algorithm.

In addition to the algorithm path parameter, the endpoint also takes an optional limit query parameter. All the algorithms return a max of 100 posts. To get a smaller set of posts, specify the limit parameter. Example: /feed/recent?limit=10

Personalized Feed

Personalized content feed algorithms are meant to generate lists of posts that are most relevant to each user. These algorithms crawl a user's social graph and activity when recommending posts. There's a time decay element in this as well.

These algorithm deployed is:

  • /feed/personal/{profile}/following which uses the Following strategy

In addition to the algorithm path parameter, the endpoint also takes an optional limit query parameter. All the algorithms return a max of 100 posts. To get a smaller set of posts, specify the limit parameter. Example: /feed/personal/karma3labs.lens/following?limit=10

API Documentation

Tryout the APIs here! — https://openapi.lens.k3l.io

Personalized content feed

Returns a list of posts based on a strategy that is personalized for the given profile.

GEThttps://lens-api.k3l.io/feed/personal/{profile}/{strategy}
Path parameters
profile*string

The Lens profile handle (with or without the .lens extension) or hex Id.

strategy*enum

The strategy name to use such as 'following'.

following
Query parameters
Response

Query succeeded.

Body
postId*string

Lens Post ID

handlestring

Lens profile handle.

mirrorsCountinteger

Number of mirrors.

commentsCountinteger

Number of comments.

collectsCountinteger

Number of collects.

upvotesCountinteger

Number of upvotes.

vnumber (float)

The internal score generated by the strategy for the post.

createdAtstring (date-time)

Block timestamp of when the post was created.

contentUristring

URI where the post content is stored.

Request
const response = await fetch('https://lens-api.k3l.io/feed/personal/{profile}/{strategy}', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
[
  {
    "postId": "text",
    "handle": "text",
    "v": 0,
    "createdAt": "2024-11-21T06:27:19.625Z",
    "contentUri": "text"
  }
]

Non-personalized content feed

Returns a list of posts based on a strategy that is not personalized.

GEThttps://lens-api.k3l.io/feed/{strategy}
Path parameters
strategy*enum

The strategy name to use such as 'recent', 'popular', 'recommended', or 'crowdsourced'.

recentpopularrecommendedcrowdsourced
Query parameters
Response

Query succeeded.

Body
postId*string

Lens Post ID

handlestring

Lens profile handle.

mirrorsCountinteger

Number of mirrors.

commentsCountinteger

Number of comments.

collectsCountinteger

Number of collects.

upvotesCountinteger

Number of upvotes.

vnumber (float)

The internal score generated by the strategy for the post.

createdAtstring (date-time)

Block timestamp of when the post was created.

contentUristring

URI where the post content is stored.

Request
const response = await fetch('https://lens-api.k3l.io/feed/{strategy}', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
[
  {
    "postId": "text",
    "handle": "text",
    "v": 0,
    "createdAt": "2024-11-21T06:27:19.625Z",
    "contentUri": "text"
  }
]

You can try out this API at this OpenAPI interfacehttps://openapi.lens.k3l.io

Last updated

Logo

Copyright 2024