Socket
Socket
Sign inDemoInstall

twitter-api-fetch

Package Overview
Dependencies
9
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    twitter-api-fetch

fetch-like implementation designed for Twitter API


Version published
Weekly downloads
36
increased by16.13%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

twitter-api-fetch

codecov Tests

fetch-like implementation designed for Twitter API

Usage

Deno

import { oauth1a } from "https://deno.land/x/twitter_api_fetch@2.1.1/mod.ts";

const fetcher = await oauth1a({
  consumerKey: "Your consumer key here.",
  secretConsumerKey: "Your consumer key (secret) here.",
  accessToken: "Your access token here.",
  secretAccessToken: "Your access token (secret) here.",
});

const response = await fetcher("/2/tweets", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    text: "大いなる力には、大いなる責任が伴う",
  }),
});

console.log(response);
console.log(await response.json());

Node.js

npm i twitter-api-fetch

# Yarn
yarn add twitter-api-fetch

# pnpm
pnpm i twitter-api-fetch
import { oauth1a } from "twitter-api-fetch";

const fetcher = await oauth1a({
  consumerKey: "Your consumer key here.",
  secretConsumerKey: "Your consumer key (secret) here.",
  accessToken: "Your access token here.",
  secretAccessToken: "Your access token (secret) here.",
});

const response = await fetcher("/2/tweets", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    text: "大いなる力には、大いなる責任が伴う",
  }),
});

console.log(response);
console.log(await response.json());

Cloudflare Workers

import { oauth1a } from "twitter-api-fetch/edge";

export interface Env {
  TWITTER_API_ACCESS_TOKEN: string;
  TWITTER_API_SECRET_ACCESS_TOKEN: string;
  TWITTER_API_CONSUMER_KEY: string;
  TWITTER_API_SECRET_CONSUMER_KEY: string;
}

export default {
  async fetch(
    _request: Request,
    env: Env,
    _ctx: ExecutionContext,
  ): Promise<Response> {
    const fetcher = await oauth1a({
      accessToken: env.TWITTER_API_ACCESS_TOKEN,
      consumerKey: env.TWITTER_API_CONSUMER_KEY,
      secretAccessToken: env.TWITTER_API_SECRET_ACCESS_TOKEN,
      secretConsumerKey: env.TWITTER_API_SECRET_CONSUMER_KEY,
    });
    const response = await fetcher(
      "/2/users/910317474951786496/tweets",
      {
        cf: {
          cacheTtl: 600,
        },
      },
    );

    if (!response.ok) {
      return new Response(
        JSON.stringify({ message: "Internal Server Error" }),
        { status: 500, headers: { "Content-Type": "application/json" } },
      );
    }

    const tweets = await response.json();

    console.log(tweets);

    return new Response(JSON.stringify(tweets), {
      headers: {
        "Content-Type": "application/json",
      },
    });
  },
};

Authentication

  • OAuth 1.0a User Context
  • OAuth 2.0 Authorization Code Flow with PKCE
  • App only
  • Basic authentication

Note Regarding OAuth 2.0 Authorization Code Flow with PKCE, twitter-api-fetch does not currently provide any functionality to assist in the process of issuing access tokens.

License

MIT License

Copyright (c) 2022 The NEXTERIAS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Keywords

FAQs

Last updated on 08 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc