Skip to content

Commit

Permalink
Add Youtube API
Browse files Browse the repository at this point in the history
  • Loading branch information
kaamil-ahamadh committed Nov 18, 2022
1 parent fec0982 commit 0d4486b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,36 @@ import { Route, Routes } from "react-router-dom";
import GlobalContext from "./context/GlobalContext";
import { HomeScreen, VideoDetailsScreen, ErrorScreen } from "../src/screens";
import { Header, Footer, Loading, SearchQuery } from "../src/components";
import { youtubeApiTrending } from "./apis/youtubeApi";

function App() {
/* States */

//Loading
const [loading, setLoading] = useState(true);

// Global States
//Search
const [userSearch, setUserSearch] = useState("");

// Global States

//UseEffect
useEffect(() => {
handleTrendingApi();
setTimeout(() => {
setLoading(false);
}, 1000);
}, []);

const handleTrendingApi = async () => {
try {
const response = await youtubeApiTrending();
console.log(response.data.contents);
} catch (error) {
console.log(error);
}
};

if (loading) {
return <Loading />;
}
Expand Down
45 changes: 45 additions & 0 deletions src/apis/youtubeApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import axios from "axios";

export const youtubeApiTrending = async () => {
try {
return await axios.get(
"https://youtube-search-and-download.p.rapidapi.com/trending",
{
params: { type: "now", hl: "en", gl: "IN" },
headers: {
"X-RapidAPI-Key": process.env.REACT_APP_YOUTUBE_RAPID_API_KEY,
"X-RapidAPI-Host": process.env.REACT_APP_YOUTUBE_RAPID_API_HOST,
},
}
);
} catch (error) {
console.log(error);
}
};

export const youtubeApiSearch = async (searchQuery) => {
try {
return await axios.get(
"https://youtube-search-and-download.p.rapidapi.com/search",
{
params: {
query: searchQuery,
next: "EogDEgVoZWxsbxr-AlNCU0NBUXRaVVVoeldFMW5iRU01UVlJQkMyMUlUMDVPWTFwaWQwUlpnZ0VMWW1VeE1rSkROWEJSVEVXQ0FRdFZNMEZUYWpGTU5sOXpXWUlCQzJaaGVrMVRRMXBuTFcxM2dnRUxaV3hrWldGSlFYWmZkMFdDQVExU1JGbFJTSE5ZVFdkc1F6bEJnZ0VMT0hwRVUybHJRMmc1Tm1PQ0FRc3pOMFU1VjNORWJVUmxaNElCQzJGaFNXcHpPRXN6YjFsdmdnRUxaMmRvUkZKS1ZuaEdlRldDQVF0clN6UXlURnB4VHpCM1FZSUJDME42VHpOaFNXVXdVbkJ6Z2dFTFNVNHdUMk5WZGtkaU5qQ0NBUXRSYTJWbGFGRTRSRjlXVFlJQkMyWk9NVU41Y2pCYVN6bE5nZ0VMZEZac1kwdHdNMkpYU0RpQ0FRdGZSQzFGT1Rsa01XSk1TWUlCQzJoQlUwNVRSSFZOY2pGUmdnRUxkREEzTVZkdE5EVnhWMDAlM0QYgeDoGCILc2VhcmNoLWZlZWQ%3D",
hl: "en",
gl: "IN",
upload_date: "t",
type: "v",
duration: "s",
features: "li;hd",
sort: "v",
},
headers: {
"X-RapidAPI-Key": process.env.REACT_APP_YOUTUBE_RAPID_API_KEY,
"X-RapidAPI-Host": process.env.REACT_APP_YOUTUBE_RAPID_API_HOST,
},
}
);
} catch (error) {
console.log(error);
}
};

0 comments on commit 0d4486b

Please sign in to comment.