Code Monkey home page Code Monkey logo

Comments (10)

SilasRodrigues19 avatar SilasRodrigues19 commented on September 24, 2024

Hey @vinaydeep26

For those days it stopped working.

I checked here now and I saw that there is this API called google-search72 which was even updated 2 days ago. I tried to integrate locally and apparently the request works but it is not rendering the information, I need to check more calmly.

image

from googlesearchapi.

SilasRodrigues19 avatar SilasRodrigues19 commented on September 24, 2024

The updates I made for the request to appear on the Network tab were as follows:

/components/Results.jsx:

import React, { useEffect } from "react";
import { useLocation } from "react-router-dom";
import ReactPlayer from "react-player";

import { useStateContext } from "../contexts/StateContextProvider";
import { Loading } from "./Loading";

export const Results = () => {
  const { results, loading, getResults, searchTerm } = useStateContext();
  const location = useLocation();

  useEffect(() => {
    if (searchTerm !== "") {
      if (location.pathname === "/videos") {
        getResults(`/search?query=${searchTerm} videos`);
      } else if(location.pathname === '/images') {
        getResults(`/search?query=${searchTerm} images`);
      } 
      else {
        getResults(`${location.pathname}?query=${searchTerm}&num=40`);
      }
    }
  }, [searchTerm, location.pathname]);

  if (loading) return <Loading />;

  switch (location.pathname) {
    case "/search":
      return (
        <div className="sm:px-56 flex flex-wrap justify-between space-y-6">
          {results?.results?.map(({ link, title }, index) => (
            <div key={index} className="md:w-2/5 w-full">
              <a href={link} target="_blank" rel="noreferrer">
                <p className="text-sm">
                  {link.length > 30 ? link.substring(0, 30) : link}
                </p>
                <p className="text-lg hover:underline dark:text-blue-300 text-blue-700  ">
                  {title}
                </p>
              </a>
            </div>
          ))}
        </div>
      );
    case "/images":
      return (
        <div className="flex flex-wrap justify-center items-center">
          {results?.results?.map(
            ({ title, link, additional_links: {href, size} }, index) => (
              <div className="sm:flex flex-1 w-110">
                <a
                  href={href}
                  target="_blank"
                  key={index}
                  rel="noreferrer"
                  className="sm:p-3 p-5"
                >
                  <img
                    src={link}
                    alt={title}
                    loading="lazy"
                    className="sm:w-150"
                  />
                  <p className="sm:w-36 w-36 break-words text-sm mt-2">
                    {title}
                  </p>
                </a>
              </div>
            )
          )}
        </div>
      );
    case "/news":
      return (
        <div className="sm:px-56 flex flex-wrap justify-between items-center space-y-6">
          {results?.entries?.map(({ id, links, source, title }) => (
            <div key={id} className="md:w-2/5 w-full ">
              <a
                href={links?.[0].href}
                target="_blank"
                rel="noreferrer "
                className="hover:underline "
              >
                <p className="text-lg dark:text-blue-300 text-blue-700">
                  {title}
                </p>
              </a>
              <div className="flex gap-4">
                <a
                  href={source?.href}
                  target="_blank"
                  rel="noreferrer"
                  className="hover:underline hover:text-blue-300"
                >
                  {" "}
                  {source?.href}
                </a>
              </div>
            </div>
          ))}
        </div>
      );
    case "/videos":
      return (
        <div className="flex flex-wrap ">
          {results?.results?.map((video, index) => (
            <div key={index} className="p-2">
              <ReactPlayer
                url={video.additional_links?.[0].href}
                controls
                width="355px"
                height="200px"
              />
            </div>
          ))}
        </div>
      );
    default:
      return "Error...";
  }
};

/contexts/StateContextProvider:

import React, { createContext, useContext, useState } from 'react';

const StateContext = createContext();
const baseUrl = 'https://google-search72.p.rapidapi.com';

export const StateContextProvider = ({ children }) => {
  const [results, setResults] = useState([]);
  const [loading, setLoading] = useState(false);
  const [searchTerm, setSearchTerm] = useState('');

  const getResults = async (url) => {
    setLoading(true);

    console.log(`${baseUrl}${url}`);

    const res = await fetch(`${baseUrl}${url}`, {
      method: 'GET',
      headers: {
        'X-RapidAPI-Key': process.env.REACT_APP_API_KEY,
        'X-RapidAPI-Host': 'google-search72.p.rapidapi.com',
      },
    });

    const data = await res.json();

    setResults(data);
    setLoading(false);
  };

  return (
    <StateContext.Provider
      value={{ getResults, results, searchTerm, setSearchTerm, loading }}
    >
      {children}
    </StateContext.Provider>
  );
};

export const useStateContext = () => useContext(StateContext);

And in the API link I mentioned, I needed to re-enroll for the free plan:

https://rapidapi.com/neoscrap-net/api/google-search72/pricing

image

As soon as I have time, I try to understand the new structure to correctly display the request information

from googlesearchapi.

vinaydeep26 avatar vinaydeep26 commented on September 24, 2024

So you got it running yet or no?

from googlesearchapi.

SilasRodrigues19 avatar SilasRodrigues19 commented on September 24, 2024

I need to change my file /components/Results.jsx to display the data correctly because it really broke. But I fixed the API problem, I just haven't committed it yet because I'm going to solve the problem completely

from googlesearchapi.

SilasRodrigues19 avatar SilasRodrigues19 commented on September 24, 2024

@vinaydeep26

I was trying to fix the map in the Results.jsx component, but the free version is limited to 25 requests per month. This API version is more limited than the previous one

image

from googlesearchapi.

vinaydeep26 avatar vinaydeep26 commented on September 24, 2024

i found two more APIs that you can use which have more requests:
https://rapidapi.com/UnlimitedAPI/api/google-web-search1
https://rapidapi.com/neoscrap-net/api/google-search72
maybe try these

from googlesearchapi.

SilasRodrigues19 avatar SilasRodrigues19 commented on September 24, 2024

I'm using this https://rapidapi.com/UnlimitedAPI/api/google-web-search1 but has 25 requests per month only

from googlesearchapi.

vinaydeep26 avatar vinaydeep26 commented on September 24, 2024

So what’s the solution? The project is obsolete

from googlesearchapi.

SilasRodrigues19 avatar SilasRodrigues19 commented on September 24, 2024

I'm working locally with this API I mentioned, but I couldn't fix the component that renders the data because it reached the monthly request limit

from googlesearchapi.

SilasRodrigues19 avatar SilasRodrigues19 commented on September 24, 2024

Hey @vinaydeep26

It was finally resolved, but the project is no longer the same as the new API google-search72 has some limitations.

The following endpoints no longer exist:

/news and /videos

The /images and /search endpoints are working, but they have a different structure and searches are more limited, both in terms of content quality and requests (limit of only 40 requests per month)

image
image
image

The project will stay like this for now, thanks for reporting.

from googlesearchapi.

Related Issues (1)

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.