Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API calls are too slow #494

Open
neelhabib opened this issue Jun 12, 2024 · 5 comments
Open

API calls are too slow #494

neelhabib opened this issue Jun 12, 2024 · 5 comments

Comments

@neelhabib
Copy link

const { GoogleAdsApi, services } = require("google-ads-api");
const keywords = ["crypto"];
const KeywordSeed = services.KeywordSeed;
const keywordSeed = new KeywordSeed({ keywords: keywords });

console.time("keywords");

(async () => {
  const client = new GoogleAdsApi({
    client_id:
      "3131313131313131313123.apps.googleusercontent.com",
    client_secret: "3131313131313131312313",
    developer_token: "131313131313131",
  });
  const customer = client.Customer({
    customer_id: "42424242423",
    refresh_token:
      "131312312313131313131231313123131231231313",
  });
  //   await customer.keywordPlanIdeas.generateKeywordHistoricalMetrics({});
  const generateKeywordIdeaResponse = await customer.keywordPlanIdeas
    .generateKeywordIdeas({
      customer_id: customer.credentials.customer_id,
      keyword_seed: keywordSeed,
    })
    .catch((e) => console.error(e));
  console.log(generateKeywordIdeaResponse.length);

  console.timeEnd("keywords");
})();

I am generating keywords ideas. The request taking approx 30 to 45 sec to complete. Is there any way to accomplish quick results.
I am using Rest API which is return within 1 to 2 seconds.
Please provide solutions.
Thanks

@alwin12
Copy link

alwin12 commented Jul 1, 2024

Do we have any updates on this? Each request is taking around 30 seconds. I'll need to use the REST API directly.

@neelhabib
Copy link
Author

Do we have any updates on this? Each request is taking around 30 seconds. I'll need to use the REST API directly.

No update on this. I am using REST API instead which too way fast as expected.

@Klyado
Copy link

Klyado commented Nov 21, 2024

Do we have any updates on this? Each request is taking around 30 seconds. I'll need to use the REST API directly.

No update on this. I am using REST API instead which too way fast as expected.

Same here. Taking sooo long 😔

@neelhabib any way to get the code you're using? Can't find the right API URL nor the params to send.
Would be highly appreciated.

@neelhabib
Copy link
Author

Do we have any updates on this? Each request is taking around 30 seconds. I'll need to use the REST API directly.

No update on this. I am using REST API instead which too way fast as expected.

Same here. Taking sooo long 😔

@neelhabib any way to get the code you're using? Can't find the right API URL nor the params to send. Would be highly appreciated.

here is the documentation link from google.

https://developers.google.com/google-ads/api/rest/reference/rest/v18/customers/generateKeywordIdeas

import accessToken from "../../../accessToken";

const fs = require("fs");
const axios = require("axios");
export default async function handler(req, res) {
  const keywords = req.body?.domain?.keywords;

  const apiUrl = `https://googleads.googleapis.com/v17/customers/_your_customer_id_here_:generateKeywordIdeas`;

  try {
    switch (req.method) {
      case "POST":
        const response = await axios.post(
          apiUrl,
          {
            keywordSeed: {
              keywords: [keywords],
            },
            pageSize: 2000,
          },

          {
            headers: {
              Authorization: `Bearer ${accessToken}`,
              "developer-token": "___your__developer_token__",
              "Content-Type": "application/json",
            },
          }
        );

        const data = response?.data?.results

        res.json(data);
      case "GET":
        res.json("hello");
    }
  } catch (error) {
    console.error("Error fetching keyword ideas:", error);
    res.json("error");
  }
}

export const config = {
  api: {
    externalResolver: true,
  },
};

@akaasten
Copy link

Wow perfect!!
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants