项目
版本

Uppy Instagram 插件

@uppy/instagram 插件允许用户从他们的 Instagram 账户导入文件。

何时使用?

当你想让用户从他们的 Instagram 账户导入文件时,应使用此功能。

Instagram 插件工作需要一个 Companion 实例。Companion 负责与 Instagram 进行身份验证、下载文件,并将其上传到目的地。这节省了用户的带宽,特别是当他们使用移动网络连接时非常有用。

你可以自托管 Companion 或者通过任何 Transloadit 计划 获得托管版本。

  • npm

    npm install @uppy/instagram
    
  • yarn

    yarn add @uppy/instagram
    
  • CDN

    <!-- 1. Add CSS to `<head>` -->
    <link href="https://releases.transloadit.com/uppy/v3.27.3/uppy.min.css" rel="stylesheet">
    
    <!-- 2. Initialize -->
    <div id="uppy"></div>
    
    <script type="module">
        import { Uppy, Instagram } from "https://releases.transloadit.com/uppy/v3.27.3/uppy.min.mjs"
        const uppy = new Uppy()
        uppy.use(Instagram, {
        // Options
        })
    </script>
    

使用方法

使用 Instagram 需要在 Uppy 和 Companion 中进行设置。

在 Uppy 中使用

import Uppy from "@uppy/core";
import Dashboard from "@uppy/dashboard";
import Instagram from "@uppy/instagram";

import "@uppy/core/dist/style.min.css";
import "@uppy/dashboard/dist/style.min.css";

new Uppy()
  .use(Dashboard, { inline: true, target: "#dashboard" })
  .use(Instagram, { companionUrl: "https://your-companion.com" });

在 Companion 中使用

前往 Meta 的 Instagram 平台 注册 API 密钥 。

如果你还没有应用程序项目,请创建一个。

在应用页面上有一个 "Redirect URIs" 字段。在这里添加:

https://$YOUR_COMPANION_HOST_NAME/instagram/redirect

如果你使用的是 Transloadit 托管的 Companion:

https://api2.transloadit.com/companion/instagram/redirect

Meta 将提供一个 OAuth 客户端 ID 和客户端密钥。

在 Companion 中配置 Instagram 密钥和密钥。对于独立的 Companion 服务器,指定环境变量:

export COMPANION_INSTAGRAM_KEY="Instagram OAuth 客户端ID"
export COMPANION_INSTAGRAM_SECRET="Instagram OAuth 客户端密钥"

当使用 Companion Node.js API 时,配置这些选项:

companion.app({
  providerOptions: {
    instagram: {
      key: "Instagram OAuth 客户端ID",
      secret: "Instagram OAuth 客户端密钥",
    },
  },
});

API

选项

id

此插件的唯一标识符( string,默认:'Instagram' )。

title

在 UI 中显示的标题/名称,如 Dashboard 标签( string,默认:'Instagram' )。

target

放置拖放区域的 DOM 元素、CSS 选择器或插件( stringElementFunction,或 UIPlugin,默认:Dashboard )。

companionUrl

指向 Companion 实例的 URL( string,默认:null )。

companionHeaders

每次向 Companion 发送请求时应随附的自定义头( Object,默认:{} )。

companionAllowedHosts

应接受 OAuth 响应的有效且授权的 URL( stringRegExp,或 Array,默认:companionUrl )。

此值可以是 stringRegExp 模式,或两者的 Array。当你有 Companion 在多个主机上运行时,这个功能很有用。否则,默认值应该足够好。

  • companionCookiesRule

此选项对应于 RequestCredentials 值string,默认:'same-origin' )。

它告诉插件是否应将 cookies 发送到 Companion

  • locale
export default {
  strings: {
    pluginNameInstagram: "Instagram",
  },
};
在本文档中