Random Image API 使用教程
Random Image API 使用教程

https://github.com/Jalen9428/random-image-api

Random Image API

中文版本

项目介绍

此项目利用Vercel+Notion数据库实现对数据库中所有图片的随机访问,更新图片无需更新github仓库或重新部署,是一个比较方便的随机图片API项目

准备工作

注册Github、Vercel以及Notion账户。

具体部署流程

1.在你的Notion工作目录下新建一个空数据库,并新建一列,类型选择“文件和媒体”,并将此列命名为“Image”(必须命名为Image,不然无法识别到图片,或者更改仓库代码)。

2.在此列下添加你的图片,可以选择直接上传或外链链接,中国用户推荐使用外链,不然图片加载速度会非常慢,请自行选择访问速度较快的图床或其他支持直链的网盘。

3.点击右上角“共享(Share)”,再次点击“发布(Publish)”,点击蓝色按钮将你的数据库公开,在你的数据库页面下复制Database IDnotion.com/p/(Database ID)?v=…),得到的结果时一串32位的id,可以检查一下id位数。或者你可以点击查看网站,notion.site/后的32位数字和字母就是Database ID。此步骤下复制的Database ID是之后Vercel部署中的NOTION_DATABASE_ID环境变量值。

4.访问Notion开发者页面,新建连接(New connection),随便输入一个连接名称(Connection name),其他无需改动,并点击按钮创建连接(Create connection)

5.进入你新建连接的页面,复制集成令牌(Integration token)下的访问令牌(Access token),这是之后Vercel部署中的NOTION_API_KEY环境变量值。

6.进入内容访问权限(Content access)选项卡,点击添加页面和数据库(Add pages & databases),选择你刚刚创建的数据库(如果没找到,搜索一下,同时可以刷新缓存)。

7.在random-image-api项目页面下,点击README中的Deploy按钮,一键部署,部署时会要求你填写环境变量NOTION_API_KEYNOTION_DATABASE_ID的值,填写之前获取到的值即可。

8.您的随机图片API已经部署完毕,您可以使用Vercel的赠送域名或使用自定义域名访问API,链接为:(您的域名)/api/random,将会自动跳转到Notion数据库中任意一张图片的连接。如果您是中国用户,由于Vercel的赠送域名在中国大陆受到DNS污染,您可能无法使用Vercel赠送域名访问,请您自行配置自定义域名,在这里我不细讲配置自定义域名的方法,请您自行搜索。

English Version

Project Introduction

This project leverages Vercel + Notion database to enable random access to all images stored in the database. Updating images does not require modifying the GitHub repository or redeploying, making it a convenient random image API solution.

Prerequisites

Sign up for GitHub, Vercel, and Notion accounts.

Detailed Deployment Process

  1. In your Notion workspace, create a new empty database, then add a new column of type “Files & media” and name this column “Image” (must be named exactly “Image”, otherwise the images won’t be recognized; alternatively, you can modify the repository code accordingly).
  2. Add your images under this column – you can either upload them directly or use external link URLs. For users in China, external links are recommended, as direct uploads may result in very slow image loading. Please choose a fast image hosting service or a cloud storage that supports direct links.
  3. Click the “Share” button in the top right corner, then click “Publish” again, and click the blue button to make your database public. On your database page, copy the Database ID (found in notion.com/p/(Database ID)?v=…). The result should be a 32‑character alphanumeric string – double‑check the length. Alternatively, you can click “View site” and look for the 32‑character alphanumeric string after notion.site/ – that is also the Database ID. The Database ID copied in this step will be used as the value for the NOTION_DATABASE_ID environment variable during Vercel deployment.
  4. Visit the Notion Developers page and create a new connection. Enter any connection name (no other changes needed), and click the “Create connection” button.
  5. On the page for your newly created integration, copy the Access token (found under “Integration token”). This will be used as the value for the NOTION_API_KEY environment variable in Vercel deployment.
  6. Go to the “Content access” tab, click “Add pages & databases”, and select the database you just created (if you can’t find it, use the search bar or refresh the cache).
  7. On the random-image-api project page, click the “Deploy” button in the README to deploy with one click. During deployment, you will be prompted to enter the environment variables NOTION_API_KEY and NOTION_DATABASE_ID – fill in the values you obtained earlier.
  8. Your random image API is now deployed. You can access it using Vercel’s provided domain or your custom domain via the endpoint: (your-domain)/api/random. The request will automatically redirect to a random image from your Notion database. For users in China, please note that Vercel’s default domain may be subject to DNS pollution, making it inaccessible. In that case, you will need to configure a custom domain. This tutorial does not cover custom domain setup in detail – please search for relevant guides.
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇
Cover
加载中...
准备就绪