├── src ├── youtube_curl.sh ├── youtube_python.py ├── youtube_nodejs.js ├── youtube_php.php ├── youtube_golang.go ├── youtube_csharp.cs └── youtube_java.java └── README.md /src/youtube_curl.sh: -------------------------------------------------------------------------------- 1 | curl --user USERNAME:PASSWORD \ 2 | 'https://realtime.oxylabs.io/v1/queries' \ 3 | -H "Content-Type: application/json" \ 4 | -d '{"source": "universal", "url": "https://www.youtube.com/watch?v=SLSGtgKWzxg", "render": "html"}' 5 | -------------------------------------------------------------------------------- /src/youtube_python.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from pprint import pprint 3 | 4 | # Structure payload. 5 | payload = { 6 | 'source': 'universal', 7 | 'url': 'https://www.youtube.com/watch?v=SLSGtgKWzxg', 8 | 'render': 'html' 9 | } 10 | 11 | # Get a response. 12 | response = requests.request( 13 | 'POST', 14 | 'https://realtime.oxylabs.io/v1/queries', 15 | auth=('USERNAME', 'PASSWORD'), # Your credentials go here 16 | json=payload 17 | ) 18 | 19 | # Instead of response with job status and results URL, this will return the 20 | # JSON response with results. 21 | pprint(response.json()) 22 | -------------------------------------------------------------------------------- /src/youtube_nodejs.js: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch'; 2 | 3 | const username = 'USERNAME'; 4 | const password = 'PASSWORD'; 5 | const body = { 6 | 'source': 'universal', 7 | 'url': 'https://www.youtube.com/watch?v=SLSGtgKWzxg', 8 | 'render': 'html', 9 | }; 10 | const response = await fetch('https://realtime.oxylabs.io/v1/queries', { 11 | method: 'post', 12 | body: JSON.stringify(body), 13 | headers: { 14 | 'Content-Type': 'application/json', 15 | 'Authorization': 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64'), 16 | } 17 | }); 18 | 19 | console.log(await response.json()); 20 | -------------------------------------------------------------------------------- /src/youtube_php.php: -------------------------------------------------------------------------------- 1 | 'universal', 5 | 'url' => 'https://www.youtube.com/watch?v=SLSGtgKWzxg', 6 | 'render' => 'html' 7 | ); 8 | 9 | $ch = curl_init(); 10 | 11 | curl_setopt($ch, CURLOPT_URL, "https://realtime.oxylabs.io/v1/queries"); 12 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 13 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); 14 | curl_setopt($ch, CURLOPT_POST, 1); 15 | curl_setopt($ch, CURLOPT_USERPWD, "USERNAME" . ":" . "PASSWORD"); //Your credentials go here 16 | 17 | $headers = array(); 18 | $headers[] = "Content-Type: application/json"; 19 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 20 | 21 | $result = curl_exec($ch); 22 | echo $result; 23 | 24 | if (curl_errno($ch)) { 25 | echo 'Error:' . curl_error($ch); 26 | } 27 | curl_close ($ch); 28 | ?> 29 | -------------------------------------------------------------------------------- /src/youtube_golang.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io/ioutil" 8 | "net/http" 9 | ) 10 | 11 | func main() { 12 | const Username = "USERNAME" 13 | const Password = "PASSWORD" 14 | 15 | payload := map[string]string{ 16 | "source": "universal", 17 | "url": "https://www.youtube.com/watch?v=SLSGtgKWzxg", 18 | "render": "html", 19 | } 20 | 21 | jsonValue, _ := json.Marshal(payload) 22 | 23 | client := &http.Client{} 24 | request, _ := http.NewRequest("POST", 25 | "https://realtime.oxylabs.io/v1/queries", 26 | bytes.NewBuffer(jsonValue), 27 | ) 28 | 29 | request.SetBasicAuth(Username, Password) 30 | response, _ := client.Do(request) 31 | 32 | responseText, _ := ioutil.ReadAll(response.Body) 33 | fmt.Println(string(responseText)) 34 | } 35 | -------------------------------------------------------------------------------- /src/youtube_csharp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Net.Http.Json; 5 | using System.Threading.Tasks; 6 | 7 | namespace OxyApi 8 | { 9 | class Program 10 | { 11 | static async Task Main() 12 | { 13 | const string Username = "USERNAME"; 14 | const string Password = "PASSWORD"; 15 | 16 | var parameters = new Dictionary<string, string>() 17 | { 18 | {"source", "universal"}, 19 | {"url", "https://www.youtube.com/watch?v=SLSGtgKWzxg"}, 20 | {"render", "html"} 21 | }; 22 | 23 | var client = new HttpClient(); 24 | 25 | Uri baseUri = new Uri("https://realtime.oxylabs.io"); 26 | client.BaseAddress = baseUri; 27 | 28 | var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/v1/queries"); 29 | requestMessage.Content = JsonContent.Create(parameters); 30 | 31 | var authenticationString = $"{Username}:{Password}"; 32 | var base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(authenticationString)); 33 | requestMessage.Headers.Add("Authorization", "Basic " + base64EncodedAuthenticationString); 34 | 35 | var response = await client.SendAsync(requestMessage); 36 | var contents = await response.Content.ReadAsStringAsync(); 37 | 38 | Console.WriteLine(contents); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/youtube_java.java: -------------------------------------------------------------------------------- 1 | import okhttp3.*; 2 | import org.json.JSONObject; 3 | 4 | public class Main implements Runnable { 5 | private static final String AUTHORIZATION_HEADER = "Authorization"; 6 | public static final String USERNAME = "USERNAME"; 7 | public static final String PASSWORD = "PASSWORD"; 8 | 9 | public void run() { 10 | JSONObject jsonObject = new JSONObject(); 11 | jsonObject.put("source", "universal"); 12 | jsonObject.put("url", "https://www.youtube.com/watch?v=SLSGtgKWzxg"); 13 | jsonObject.put("render", "html"); 14 | 15 | Authenticator authenticator = (route, response) -> { 16 | String credential = Credentials.basic(USERNAME, PASSWORD); 17 | 18 | return response 19 | .request() 20 | .newBuilder() 21 | .header(AUTHORIZATION_HEADER, credential) 22 | .build(); 23 | }; 24 | 25 | var client = new OkHttpClient.Builder() 26 | .authenticator(authenticator) 27 | .build(); 28 | 29 | var mediaType = MediaType.parse("application/json; charset=utf-8"); 30 | var body = RequestBody.create(jsonObject.toString(), mediaType); 31 | var request = new Request.Builder() 32 | .url("https://realtime.oxylabs.io/v1/queries") 33 | .post(body) 34 | .build(); 35 | 36 | try (var response = client.newCall(request).execute()) { 37 | assert response.body() != null; 38 | System.out.println(response.body().string()); 39 | } catch (Exception exception) { 40 | System.out.println("Error: " + exception.getMessage()); 41 | } 42 | 43 | System.exit(0); 44 | } 45 | 46 | public static void main(String[] args) { 47 | new Thread(new Main()).start(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |