Code Monkey home page Code Monkey logo

Comments (4)

vineetjk avatar vineetjk commented on May 27, 2024

lets do it

from api-reference.

biplobsd avatar biplobsd commented on May 27, 2024

@D-K-P
I tried with BEARER_TOKEN on OAuth2Bearer but I unable to overwrite the createTweet endpoint for use the OAuth 1.0a auth. https://github.com/twitterdev/twitter-api-typescript-sdk/blob/0d12a20a76d6dd9c346decf9cc80bc611975d43f/src/gen/Client.ts#L897C6-L897C31

image

Here I tried to change the endpoint
image

So now I'm using the axios for direct interact with the path. Now I'm getting this error -

{
  errors: [
    {
      message: 'You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) only. If you need access to this endpoint, you may need a different access level. You can learn more here: https://developer.twitter.com/en/portal/product',
      code: 453
    }
  ]
}

Is it need for pro account?

Here is the code

import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
import z from "zod";
import axios from "axios";

const client = new TriggerClient({
  id: "api-reference",
});

client.defineJob({
  id: "tweet-x",
  name: "Tweet X",
  version: "1.0.0",
  trigger: eventTrigger({
    name: "tweet-x",
    schema: z.object({
      text: z.string(),
    }),
  }),
  run: async (payload, io, ctx) => {
    const { text } = payload;

    // Wrap an SDK call in io.runTask so it's resumable and displays in logs
    await io.runTask(
      "Tweet X",
      async () => {
        try {
          await axios.post(
            "https://api.twitter.com/1.1/statuses/update.json",
            {
              status: text,
            },
            {
              headers: {
                Authorization: `Bearer ${process.env.X_BEARER_TOKEN}`,
                "Content-Type": "application/json",
              },
            }
          );
        } catch (e: any) {
          console.log(e.response.data);
        }
      },

      // Add metadata to the task to improve the display in the logs
      { name: "Tweet X", icon: "twitter" }
    );
  },
});

// These lines can be removed if you don't want to use express
import { createExpressServer } from "@trigger.dev/express";
createExpressServer(client);

from api-reference.

gjohnsx avatar gjohnsx commented on May 27, 2024

@biplobsd The free tier only allows OAuth 2.0 with PKCE
image.

Since OAuth 2.0 with PKCE requires user interaction, this poses a challenge in a background job.

The Basic tier ($100/month) allows OAuth 1.0a, and the 1.0 endpoint would probably work for a background job.

from api-reference.

biplobsd avatar biplobsd commented on May 27, 2024

Hey @gjohnsx thanks, I did follow this code https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/0d1587147d3bf8338b5fea2b4e5bb56d37f5c2b6/Manage-Tweets/create_tweet.js#L91

from api-reference.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.