This topic was automatically generated from Slack. You can find the original thread here.
Further to the above, I have it sending the file to Google drive, but it won't let me name the file or put it in the right parent. It always appears as Untitled. The data object doesn't seem to send properly.
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
twitter: {
type: "app",
app: "twitter",
},
tweet_id: {
type: "string",
label: "Tweet ID",
description: "The ID of the tweet to retrieve images from",
},
google_drive: {
type: "app",
app: "google_drive",
},
},
async run({ steps, $ }) {
const response = await axios($, {
method: "GET",
url: `https://api.twitter.com/2/tweets/${this.tweet_id}`,
params: {
"tweet.fields": "attachments",
"media.fields": "url",
"expansions": "attachments.media_keys",
},
headers: {
Authorization: `Bearer ${this.twitter.$auth.oauth_access_token}`,
},
});
const mediaKeys = response.includes?.media?.map(media => media.media_key);
const images = response.includes?.media
?.filter(media => mediaKeys.includes(media.media_key) && media.type === "photo")
.map(photo => ({ url: photo.url }));
for (const image of images) {
await axios($, {
method: "POST",
url: `https://www.googleapis.com/upload/drive/v3/files?uploadType=media`,
headers: {
Authorization: `Bearer ${this.google_drive.$auth.oauth_access_token}`,
"Content-Type": "image/jpeg",
},
data: {
name: "TweetImage.jpg",
parents: "1Uv_REDACTED7WzXE8h4",
},
data: await axios($, { url: image.url, responseType: "arraybuffer" }),
});
}
return images;
},
});