Giter Site home page Giter Site logo

Comments (2)

dandv avatar dandv commented on August 21, 2024

Seems like a duplicate of #29 - can you look into setting the subdomain to upload instead of api?

We do need better documentation for the subdomains, CC @peterpme

from twitter-lite.

gregphillips03 avatar gregphillips03 commented on August 21, 2024

@dandv
Thanks for your response. I actually tried that in the past (realized the above example I posted contained an immutable)

I can fire off text tweets, but still images fail.
`import Twitter from "twitter-lite";
import { success, failure } from "./libs/response-lib";

export async function main(event, context, callback) {
const data = JSON.parse(event.body);
const client = new Twitter({
subdomain: "api",
consumer_key: "REDACTED",
consumer_secret: "REDACTED",
access_token_key: "REDACTED",
access_token_secret: "REDACTED"
});
const upload_client = new Twitter({
subdomain: "upload",
consumer_key: "REDACTED",
consumer_secret: "REDACTED",
access_token_key: "REDACTED",
access_token_secret: "REDACTED"
});

if(data.img)
{
try
{
const url = await upload_client.post("media/upload", null, {
media_data: data.img,
});
const resp = await client.post("statuses/update", null, {
status: data.tweet,
media_ids: url.media_id_string,
});
callback(null, success(resp.id_str));
} catch (e) {
console.log(e);
callback(null, failure({ status: e}));
}
}
else
{
try
{
const resp = await client.post("statuses/update", null, {
status: data.tweet,
/* lat: 37.7821120598956,
long: -122.400612831116,
display_coordinates: true,*/
});
callback(null, success(resp.id_str));
} catch (e) {
console.log(e);
callback(null, failure({ status: false }));
}
}

}`

The try block catches this:
{name: FetchError,
type: invalid-json,
message: invalid json response body at https://upload.twitter.com/1.1/media/upload.json?media_data=(all of my b64 encoded image) reason: Unexpected end of JSON input}

But I'm not sure where that comes from; i.e., Twitter or my server.

At any rate, it looks like a valid JSON object isn't getting sent? Possibly when the payload is bundled and sent off? I'm lost on this one.

from twitter-lite.

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.