googleapis / google-api-nodejs-client

Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
https://googleapis.dev/nodejs/googleapis/latest/
Apache License 2.0
11.34k stars 1.91k forks source link

How to upload media files via API to Campaign manager 360 #2975

Open JoseLuisCR2022 opened 2 years ago

JoseLuisCR2022 commented 2 years ago

Hello, I am using the google.dfareporting library to connect my application to Campaign manager 360, and in the creativeAssets.insert method, I can upload the metadata of a media file. My question is, is there any other method to upload media files in this library?

Or is it that the only way to do it is by making a post to the following url? https://dfareporting.googleapis.com/upload/dfareporting/v3.5/userprofiles/{profileId}/creativeAssets/{advertiserId}/creativeAssets

Could you show me an example to upload media files to Campaign manager 360 from the API? I've been after this for a long time and I can't solve it.

Thank you very much!

Muratcol commented 1 year ago

Is there anyone to help with this? I can't upload media file either. I've tried these so far.


const auth = new google.auth.OAuth2();
auth.setCredentials({
    access_token: this.platformSecrets.accessToken
});

// Acquire an auth client, and bind it to all future calls
google.options({ auth: auth });

const dfareporting = google.dfareporting('v4');

const tmpPath = "./tmp/testimage.png";
const fileData = Readable.from(tmpPath);

const res = await dfareporting.creativeAssets.insert({
    advertiserId: advertiserId,
    profileId: profileId,
    media: {
        mimeType: "image/png",
        body: fileData,
    },
    requestBody: {
        assetIdentifier: {
            name: "961d18ac-d8d7-43a2-b240-33cfcbb6acad.png",
            type: "HTML_IMAGE",
        }
    }
});

This is the image file I'm trying to upload: link

And I'm constantly having this error:

Error: 19023 : The dimensions of creative asset "961d18ac-d8d7-43a2-b240-33cfcbb6acad.png" are not valid.