![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Cams - Chaturbate API V2 parsing via JavaScript
Have you wanted to build your own cams page from the Chaturbate API?
This is a little bit of code to help get you started. It is based around Chaturbates API Version 2. The biggest change between Version 1 and Version 2 was that Version 2 wants the client IP to be passed in on the API request. This allows Chaturbate to filter the results based on what cams they allow to be shown in what region. With Version 1, the most common usage is to pull the results of the API server side and then cache it there, either as a file or in a database. Then dole out the results from the cache on each page hit. Typically you would do a pull from Chaturbate every 2-5 minutes to keep the cams fresh. With Version 2, it is expected that you will pull from the API on every page hit with the client ip for filtering. This means that instead of hitting the API once every 2-5 minutes, you are hitting it on every page hit. This is considerably more overhead for your server to handle. The solution? Move the API handling onto the client side. How do you do that? Using javascript and/or jquery. The following code is the javascript I came up with to do the API call and parse in the client's browser. It has been tested in Chrome, Opera and Firefox. It is a simple little bit of code that for most practical uses must be expanded upon. It will work as is but really should have other things with it, things like a design and text, ya know? All those cool web things. I am listing 2 different ways to pull in the API. The first is pure javascript, the second uses a jquery call to the AJAX object. To use the jquery version you need to include the jquery libraries. If you are already using jquery on your pages then it makes the most sense to use the jquery version. However, if you do not use jquery, are trying to keep your page load as low as possible, or are just a minimalist at heart, then you might want to use the pure javascript version. Either way, there are 2 parts. Part 1 is pull in the API data. Part 2 is parse the API data and display it. I have included some comments in the code to help you figure out what is happening but I left some for you to figure out yourself. I am including in here 2 working demos for you to view. Look under the sheets, play with the code. The code is running from a .php file. You could almost do all of this with pure javascript but unfortunately you cannot get ahold of the user's ip in javascript. You either have to grab it from your server or from a 3rd party service. I decided that the best way to grab it was from my server and I use php to accomplish that. Since I am already in a php file I decided to utilize a little more code to make the solution a little more dynamic. Have fun. Code:
// Chaturbate API Version 2 // xml feed pull and parse using javascript called from php // by sarettah - Hatteras Designs 2021 // sarettah AT hatterasdesigns.com // requires jquery libraries for the jquery ajax call // could be done pure client side with the exception of the user ip. // that would have to be called from a service or injected here as I did // this section would go near the top of the page to make for easy editing <?php // edit area $wmid='chaturbate webmaster Id'; $tag='bigdick'; $gender='t'; $limit=50; $camsdiv='name of cams div'; // end of edit area // construct the api url $api_url="https://chaturbate.com/api/public/affiliates/onlinerooms/?wm=" . $wmid . "&format=xml&client_ip=" . $_SERVER['REMOTE_ADDR']; if($limit>0) { $api_url .="&limit=" . $limit; } if($tag>'') { $api_url .="&tag=" . $tag; } if($gender>'') { $api_url .="&gender=" . $genderl; } ?> // Here are 2 different ways to pull in the xml feed into the page // both methods call the parse data function. // Either of these would appear in your page somewhere after the cams div // Can be called inline in the page OR from the document ready function // Pulling the xml page via pure javascript AJAX call <script> pathin="<?php echo $api_url; ?>"; if (window.XMLHttpRequest) { dirpage=new XMLHttpRequest(); } else { dirpage=new ActiveXObject("Microsoft.XMLHTTP"); } dirpage.onreadystatechange=function() { if (dirpage.readyState==4 && dirpage.status==200) { parse_data(dirpage.responseText, "<?php echo $camsdiv; ?>"); } dirpage.open("GET",pathin,true); dirpage.send(); } </script> // OR //Pulling the xml page via a jquery AJAX call <script> $.ajax({ dataType: "html", url: "<?php echo $api_url; ?>", success: function (data) { //console.log(data); parse_data(data, "<?php echo $camsdiv; ?>"); } }); </script> <script> // The parse data function parses the xml data and formats the cam element division. // It then appends the result to the cams div function parse_data(data, camsdiv) { parser = new DOMParser(); xmlDoc = parser.parseFromString(data,"text/xml"); x=xmlDoc.getElementsByTagName("username"); txt=''; for (i = 0; i < x.length ;i++) { // construct your cam element here // for example txt +='<div>'; txt +='<a href=' + xmlDoc.getElementsByTagName("chatroom_url_revshare")[i].childNodes[0].nodeValue; txt +='Username: ' + xmlDoc.getElementsByTagName("username")[i].childNodes[0].nodeValue + '<br>'; txt +='<img src=' + xmlDoc.getElementsByTagName("image_url")[i].childNodes[0].nodeValue + '><br>'; // use other xml elements from the api as needed.......... // each element is called using the getelementsbytagname function and displaying their respective values txt +='</a>'; txt +='</div>'; // add the element to the div document.getElementById(camsdiv).innerHTML +=txt; txt=''; } } </script> .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Example 1 - Using Javascript for the ajax api call:
https://madspiders.com/demo/cb_apiv2_demo1.php Example 1 source code: Code:
<?php // edit area $wmid='xxxxx'; $tag='18'; $gender='f'; $limit=32; $camsdiv='camsdiv'; // end of edit area // construct the api url $api_url="https://chaturbate.com/api/public/affiliates/onlinerooms/?wm=" . $wmid . "&format=xml&client_ip=" . $_SERVER['REMOTE_ADDR']; if($limit>0) { $api_url .="&limit=" . $limit; } if($tag>'') { $api_url .="&tag=" . $tag; } if($gender>'') { $api_url .="&gender=" . $gender; } ?> <html> <head> <base href="https://gfy.com/" /><!--[if IE]></base><![endif]--> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Example of pulling CB API Version 2</title> <script> function parse_data(data, camsdiv) { parser = new DOMParser(); xmlDoc = parser.parseFromString(data,"text/xml"); x=xmlDoc.getElementsByTagName("username"); txt=''; for (i = 0; i < x.length ;i++) { txt +='<div style="float:left;width:25%;margin-bottom:10px;padding:right:10px;text-align:center;">'; txt +='<a rel=nofollow style="color:#000000;font-weight:bold;" href=' + xmlDoc.getElementsByTagName("chat_room_url_revshare")[i].childNodes[0].nodeValue + '>'; txt +=xmlDoc.getElementsByTagName("username")[i].childNodes[0].nodeValue + '<br>'; txt +='<img style="max-width:90%;" src=' + xmlDoc.getElementsByTagName("image_url")[i].childNodes[0].nodeValue + '><br>'; txt +='</a>'; txt +='</div>'; document.getElementById(camsdiv).innerHTML +=txt; txt=''; } } </script> </head> <body> <div style="width:100%;text-align:center;"> <h1>Example of pulling Chaturbate API Version 2 using pure javascript</h1> <br> <div name="camsdiv" id="camsdiv" style="margin-left:15px;"> </div> </div> <script> pathin="<?php echo $api_url; ?>"; if (window.XMLHttpRequest) { dirpage=new XMLHttpRequest(); } else { dirpage=new ActiveXObject("Microsoft.XMLHTTP"); } dirpage.onreadystatechange=function() { if (dirpage.readyState==4 && dirpage.status==200) { parse_data(dirpage.responseText, "<?php echo $camsdiv; ?>"); } } dirpage.open("GET",pathin,true); dirpage.send(); </script> </body> </html>
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Example 2: Using jquery for the ajax api call:
https://madspiders.com/demo/cb_apiv2_demo2.php Example 2 source code: Code:
<?php // edit area $wmid='xxxxx'; $tag='18'; $gender='f'; $limit=32; $camsdiv='camsdiv'; // end of edit area // construct the api url $api_url="https://chaturbate.com/api/public/affiliates/onlinerooms/?wm=" . $wmid . "&format=xml&client_ip=" . $_SERVER['REMOTE_ADDR']; if($limit>0) { $api_url .="&limit=" . $limit; } if($tag>'') { $api_url .="&tag=" . $tag; } if($gender>'') { $api_url .="&gender=" . $gender; } ?> <html> <head> <base href="https://gfy.com/" /><!--[if IE]></base><![endif]--> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Example of pulling CB API Version 2</title> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script> function parse_data(data, camsdiv) { parser = new DOMParser(); xmlDoc = parser.parseFromString(data,"text/xml"); x=xmlDoc.getElementsByTagName("username"); txt=''; for (i = 0; i < x.length ;i++) { txt +='<div style="float:left;width:25%;margin-bottom:10px;padding:right:10px;text-align:center;">'; txt +='<a rel=nofollow style="color:#000000;font-weight:bold;" href=' + xmlDoc.getElementsByTagName("chat_room_url_revshare")[i].childNodes[0].nodeValue + '>'; txt +=xmlDoc.getElementsByTagName("username")[i].childNodes[0].nodeValue + '<br>'; txt +='<img style="max-width:90%;" src=' + xmlDoc.getElementsByTagName("image_url")[i].childNodes[0].nodeValue + '><br>'; txt +='</a>'; txt +='</div>'; document.getElementById(camsdiv).innerHTML +=txt; txt=''; } } </script> </head> <body> <div style="width:100%;text-align:center;"> <h1>Example of pulling Chaturbate API Version 2 using javascript and AJAX</h1> <br> <div name="camsdiv" id="camsdiv" style="margin-left:15px;"> </div> </div> <script> $.ajax({ dataType: "html", url: "<?php echo $api_url; ?>", success: function (data) { //console.log(data); parse_data(data, "<?php echo $camsdiv; ?>"); } }); </script> </body> </html>
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
For the record the <base href tag is not actually part of the source code. GFY is inserting that into the post.
Code:
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: Aug 2005
Location: YUROP
Posts: 8,592
|
sarettah to the rescue as always, big thumbs up ;)
__________________
![]() Anal Webcams | Kinky Trans Cams Live | Hotwife XXX Tube | Get your Proxies here |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
making it rain
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 22,004
|
Nicely done
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Industry Role:
Join Date: Feb 2005
Location: Southern California
Posts: 3,728
|
Great stuff, sarretah knows his shit.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Registered User
Industry Role:
Join Date: Nov 2019
Posts: 7
|
Thanks for posting this. We encourage all affiliates to use the new API where possible.
FYI when calling from the client side, you do not need to pass the ip, you can just set it to "request_ip". Please see our documentation (chaturbate[dot]com/affiliates/promotools/api_usersonline/) for more information. ![]()
__________________
Chaturbate Affiliate Support: [email protected] |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Too lazy to set a custom title
Industry Role:
Join Date: Dec 2004
Location: Happy in the dark.
Posts: 92,975
|
We love you, sarettah . . . even though you hate us.
__________________
FLASH SALE INSANITY! deal with a 100% Trusted Seller Buy Traffic Spots on a High-Quality Network 1 Year or Lifetime — That’s Right, Until the Internet Explodes! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
Nice! I need to do more with cams, traffic for me has been going up.
![]()
__________________
![]() I've referred over $1.7mil in spending this past year, you should join in. ![]() ![]() I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years.. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
Thanks for that. I will make a note of it. Here is the link for the docs (You really need to post more there Kitt. Get up there above 30 posts so you can post links and show us your tits and all that). https://chaturbate.com/affiliates/pr...i_usersonline/ You need to be logged in to chaturbate to read the docs Don't have a Chaturbate account? You can sign up here with my ref code https://www.camfoxes.com/webcams/webmaster_signup.htm Or you can sign up directly at Chaturbate https://chaturbate.com/affiliates/ Bith links load real slow tright now so please be patient.
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
What?? When did I ever say I hated you (or anybody).
You are one of my favorite posters. .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
The Chaturbate link in my sig loads faster, so I think people should use that one instead.
![]()
__________________
![]() I've referred over $1.7mil in spending this past year, you should join in. ![]() ![]() I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years.. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Hmm. I was just putting together a new demo using the info that Kitt provided.
During testing I noticed that it loaded really slowly. So, I went back and looked at the other 2 demos I posted and they are now seeming to take a while to load, about 15 seconds. Earlier they were popping right in. Don't know if the api is running slow or what the issue is. I just know it was working fine and now it is a slow load. .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 | |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
Quote:
__________________
![]() I've referred over $1.7mil in spending this past year, you should join in. ![]() ![]() I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years.. ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Sample using just javascript - no php. Using request_ip in the client_ip parameter.
https://madspiders.com/demo/cb_apiv2_demo3.htm Source: Code:
<html> <head> <base href="https://gfy.com/" /><!--[if IE]></base><![endif]--> <base href="https://gfy.com/" /><!--[if IE]></base><![endif]--> <base href="https://gfy.com/" /><!--[if IE]></base><![endif]--> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Example of pulling CB API Version 2</title> <script> // edit area var wmid='xxxxx'; var tag='18'; var gender='f'; var limit=32; var camsdiv='camsdiv'; // end of edit area // construct the api url api_url="https://chaturbate.com/api/public/affiliates/onlinerooms/?wm=" + wmid + "&format=xml&client_ip=request_ip"; if(limit>0) { api_url +="&limit=" + limit; } if(tag>'') { api_url +="&tag=" + tag; } if(gender>'') { api_url +="&gender=" + gender; } </script> <script> function parse_data(data, camsdiv) { parser = new DOMParser(); xmlDoc = parser.parseFromString(data,"text/xml"); x=xmlDoc.getElementsByTagName("username"); txt=''; for (i = 0; i < x.length ;i++) { txt +='<div style="float:left;width:25%;margin-bottom:10px;padding:right:10px;text-align:center;">'; txt +='<a rel=nofollow style="color:#000000;font-weight:bold;" href=' + xmlDoc.getElementsByTagName("chat_room_url_revshare")[i].childNodes[0].nodeValue + '>'; txt +=xmlDoc.getElementsByTagName("username")[i].childNodes[0].nodeValue + '<br>'; txt +='<img style="max-width:90%;" src=' + xmlDoc.getElementsByTagName("image_url")[i].childNodes[0].nodeValue + '><br>'; txt +='</a>'; txt +='</div>'; document.getElementById(camsdiv).innerHTML +=txt; txt=''; } } </script> </head> <body> <div style="width:100%;text-align:center;"> <h1>Example of pulling Chaturbate API Version 2 using just javascript</h1> <br> <div name="camsdiv" id="camsdiv" style="margin-left:15px;"> </div> </div> <script> if (window.XMLHttpRequest) { dirpage=new XMLHttpRequest(); } else { dirpage=new ActiveXObject("Microsoft.XMLHTTP"); } dirpage.onreadystatechange=function() { if (dirpage.readyState==4 && dirpage.status==200) { parse_data(dirpage.responseText, camsdiv); } } dirpage.open("GET",api_url,true); dirpage.send(); </script> </body> </html> .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
Yeah but you aren't real well known for that thinking stuff. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
You're thinking of Colmike7
__________________
![]() I've referred over $1.7mil in spending this past year, you should join in. ![]() ![]() I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years.. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
I try not to think of any of you.
.
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
__________________
![]() I've referred over $1.7mil in spending this past year, you should join in. ![]() ![]() I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years.. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#21 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
All the demos seem to be working fine now.
That is one of the problems of pulling teh api every hit, you become a slave to the api. If the data from the api is stored on the server then you can reload the old data again when the api pull fails. Might be a way to delay clearing the page on a hit so that you could check for a good return but I am not sure what that way would be at the moment. Have ot think on that. .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#22 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
I just had a conversation with another programmer (whom I respect very much). He had seen the code and suggested a couple of changes in the .php versions of the code.
When getting the ip I was simply using the Server var for the Remote Ip ($_SERVER['REMOTE_ADDR']). He suggested that for someone hosting with a forwarding service, such as cloudflare, that the Remote Addr var would always return Cloudflare's ip. So to get to the real ip we have to do a little shuffling through the various server vars we have available and the code ends up looking something like: Code:
$clientip=''; if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != "") { $clientip = addslashes($_SERVER['HTTP_CLIENT_IP']); } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != "") { $clientip = addslashes($_SERVER['HTTP_X_FORWARDED_FOR']); } else { $clientip = addslashes($_SERVER['REMOTE_ADDR']); } So I am changing up the 2 php demos to utilize this methodology. Thanks to K0nr4d (https://gfy.com/members/k0nr4d/) for the advice. https://www.mechbunny.com/ is Konr4d's baby if you did not know that already. .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#23 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
https://madspiders.com/demo/cb_apiv2_demo1.php
Demo 1 new source code: Code:
<?php // edit area $wmid='JkjyU'; $tag='18'; $gender='f'; $limit=32; $camsdiv='camsdiv'; // end of edit area // pulling client ip $client_ip=''; if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != "") { $clientip = addslashes($_SERVER['HTTP_CLIENT_IP']); } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != "") { $clientip = addslashes($_SERVER['HTTP_X_FORWARDED_FOR']); } else { $clientip = addslashes($_SERVER['REMOTE_ADDR']); } // construct the api url $api_url="https://chaturbate.com/api/public/affiliates/onlinerooms/?wm=" . $wmid . "&format=xml&client_ip=" . $clientip; if($limit>0) { $api_url .="&limit=" . $limit; } if($tag>'') { $api_url .="&tag=" . $tag; } if($gender>'') { $api_url .="&gender=" . $gender; } ?> <html> <head> <base href="https://gfy.com/" /><!--[if IE]></base><![endif]--> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Example of pulling CB API Version 2</title> <script> function parse_data(data, camsdiv) { parser = new DOMParser(); xmlDoc = parser.parseFromString(data,"text/xml"); x=xmlDoc.getElementsByTagName("username"); txt=''; for (i = 0; i < x.length ;i++) { txt +='<div style="float:left;width:25%;margin-bottom:10px;padding:right:10px;text-align:center;">'; txt +='<a rel=nofollow style="color:#000000;font-weight:bold;" href=' + xmlDoc.getElementsByTagName("chat_room_url_revshare")[i].childNodes[0].nodeValue + '>'; txt +=xmlDoc.getElementsByTagName("username")[i].childNodes[0].nodeValue + '<br>'; txt +='<img style="max-width:90%;" src=' + xmlDoc.getElementsByTagName("image_url")[i].childNodes[0].nodeValue + '><br>'; txt +='</a>'; txt +='</div>'; document.getElementById(camsdiv).innerHTML +=txt; txt=''; } } </script> </head> <body> <div style="width:100%;text-align:center;"> <h1>Example of pulling Chaturbate API Version 2 using pure javascript</h1> <br> <div name="camsdiv" id="camsdiv" style="margin-left:15px;"> </div> </div> <script> pathin="<?php echo $api_url; ?>"; if (window.XMLHttpRequest) { dirpage=new XMLHttpRequest(); } else { dirpage=new ActiveXObject("Microsoft.XMLHTTP"); } dirpage.onreadystatechange=function() { if (dirpage.readyState==4 && dirpage.status==200) { parse_data(dirpage.responseText, "<?php echo $camsdiv; ?>"); } } dirpage.open("GET",pathin,true); dirpage.send(); </script> </body> </html>
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#24 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
https://madspiders.com/demo/cb_apiv2_demo2.php
Demo 2 new source code: Code:
<?php // edit area $wmid='JkjyU'; $tag='18'; $gender='f'; $limit=32; $camsdiv='camsdiv'; // end of edit area // pulling client ip $client_ip=''; if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != "") { $clientip = addslashes($_SERVER['HTTP_CLIENT_IP']); } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != "") { $clientip = addslashes($_SERVER['HTTP_X_FORWARDED_FOR']); } else { $clientip = addslashes($_SERVER['REMOTE_ADDR']); } // construct the api url $api_url="https://chaturbate.com/api/public/affiliates/onlinerooms/?wm=" . $wmid . "&format=xml&client_ip=" . $clientip; if($limit>0) { $api_url .="&limit=" . $limit; } if($tag>'') { $api_url .="&tag=" . $tag; } if($gender>'') { $api_url .="&gender=" . $gender; } ?> <html> <head> <base href="https://gfy.com/" /><!--[if IE]></base><![endif]--> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Example of pulling CB API Version 2</title> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script> function parse_data(data, camsdiv) { parser = new DOMParser(); xmlDoc = parser.parseFromString(data,"text/xml"); x=xmlDoc.getElementsByTagName("username"); txt=''; for (i = 0; i < x.length ;i++) { txt +='<div style="float:left;width:25%;margin-bottom:10px;padding:right:10px;text-align:center;">'; txt +='<a rel=nofollow style="color:#000000;font-weight:bold;" href=' + xmlDoc.getElementsByTagName("chat_room_url_revshare")[i].childNodes[0].nodeValue + '>'; txt +=xmlDoc.getElementsByTagName("username")[i].childNodes[0].nodeValue + '<br>'; txt +='<img style="max-width:90%;" src=' + xmlDoc.getElementsByTagName("image_url")[i].childNodes[0].nodeValue + '><br>'; txt +='</a>'; txt +='</div>'; document.getElementById(camsdiv).innerHTML +=txt; txt=''; } } </script> </head> <body> <div style="width:100%;text-align:center;"> <h1>Example of pulling Chaturbate API Version 2 using javascript and AJAX</h1> <br> <div name="camsdiv" id="camsdiv" style="margin-left:15px;"> </div> </div> <script> $.ajax({ dataType: "html", url: "<?php echo $api_url; ?>", success: function (data) { //console.log(data); parse_data(data, "<?php echo $camsdiv; ?>"); } }); </script> </body> </html>
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#25 | |
Too lazy to set a custom title
Industry Role:
Join Date: Dec 2004
Location: Happy in the dark.
Posts: 92,975
|
Quote:
![]()
__________________
FLASH SALE INSANITY! deal with a 100% Trusted Seller Buy Traffic Spots on a High-Quality Network 1 Year or Lifetime — That’s Right, Until the Internet Explodes! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#26 | |
making it rain
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 22,004
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#27 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
![]() .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#28 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
So based on what Fuzebox said, if you are hosting on cloudflare and were doing this with php you would want to check for Cloudflare's custom server var (HTTP_CF_CONNECTING_IP) for handling the ip.
Code:
$clientip=''; if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && $_SERVER['HTTP_CF_CONNECTING_IP'] != "") { $clientip = addslashes($_SERVER['HTTP_CF_CONNECTING_IP']); } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != "") { $clientip = addslashes($_SERVER['HTTP_CLIENT_IP']); } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != "") { $clientip = addslashes($_SERVER['HTTP_X_FORWARDED_FOR']); } else { $clientip = addslashes($_SERVER['REMOTE_ADDR']); }
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#29 | |
Confirmed User
Industry Role:
Join Date: Aug 2005
Location: YUROP
Posts: 8,592
|
Quote:
__________________
![]() Anal Webcams | Kinky Trans Cams Live | Hotwife XXX Tube | Get your Proxies here |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#30 |
Confirmed User
Industry Role:
Join Date: Mar 2013
Location: Internet
Posts: 2,425
|
Sarettah you are the best! Thank you for sharing this with us! You already helped me and other people a lot around here
![]()
__________________
Make Money With: Chaturbate |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#31 |
Confirmed User
Industry Role:
Join Date: Mar 2019
Posts: 89
|
Can you tell me what is the advantage of using API version 2? Because version 1 is quite functional, and there is no such "problem" with ip.
Thank you |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#32 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
I do not know what advantages Chaturbate intended on v2 versus v1. I can tell you the advantages I see, but it will be totally from my perspective. V1 was never really (imho) intended to be pulled on every hit. It returns all cams every time you call it. Each time it is called you have to process through the entire set of cams to do the various things you want to do. V2 allows several passins that limit the return set. limit= controls the number of records coming back offset= controls where in the return set to start exhibitionist= I am not sure what that will do, have not explored it yet, gender= allows you to select a single gender or all genders region= allows you to return cams for just a certain region tag= returns records for certain tags hd= returns records for hd cams Then there is the client_ip parameter. This allows Chaturbate to filter based on a performers setting whether the cam should appear in the set based on the users country or locality. Version 1 has a field for countries allowed but it has always been empty. If it was filled it would have been up to you to do a lookup by ip to see if the user on your site should see the cam or not. This should eliminate some of the issues of putting a cam up and when you click it coming back saying that you are not allowed to see it. These new parameters allow you to more finitely control the return set. It also allows the api to be much more efficient in that it does not have to be returning as many records and you don't have to handle as many records. So, with V2 you can realistically call it on every hit and still have a fast site. There are disadvantages too. With Version 2 it is harder to do certain things. For example, I have several sites that are based off the age of the model (18yearoldcams, 1821camgirls, milffoxes(coming)). To do those with V2, using it the way it is intended, would be a major pain in the ass as there is no pass in to return just certain age cams. I would have to circumvent what Chaturbate wants to do and still use V2 like it was V1, pulling it into the database so that I could spit out just the cams I want. I also like to do certain sorts. By age, location, etc. Doing these effectively with V2 would be another PITA. You would have to pull in all cams, sort them and then present the proper set. So again, I would probably be circumventing Chaturbate's intended use of V2 and instead use it as I use V1 and load it all to a database every 5 minutes. Another disadvantage showed itself yesterday. While I was making this thread, the api slowed down for some reason. This made all my demos break basically. I don't have to worry about that on the sites I am loading using V1. On those I load a database. If the API does not return for me I just use the old set of cams until the API comes back. I am never without cams. That is not true if you are using V2 on every hit. On V2, you are basically presenting what is in the api return, no api return, no cams. I am sure there will be workarounds to handle that but using it as intended, there is not. I think V1 will still has it's place and there are so many sites using it that I doubt that Chaturbate will be turning it off anytime soon. I have a note in Chaturbate right now asking if they have a planned end of life date on V1 as I use it all over the place. That is my take on it for what it is worth and I guarantee that it is worth every cent you paid for it. Edited in: I forgot to list what might be the biggest advantage although I did mention it in the OP. With V2 you can create a workable client side only solution. V1 did not really allow that because of the overhead involved in handling all the cams on every api call. Since you can limit the number of cams on V2 through the various passins you can create a client side solution that works. This moves a shitload of infrastructure and bandwidth off of your server and on to the client. This should result in lower costs and more efficient page delivery. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#33 | |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
Quote:
*I also heard it was for accounts that are also not age verified yet, which also seemed weird. Maybe the article I read is wrong, idk.
__________________
![]() I've referred over $1.7mil in spending this past year, you should join in. ![]() ![]() I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years.. ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#34 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
So, of all the thousands of cams on line at that time only 1 was marked exhibitionist so I don't know that the parameter is significant. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#35 | |
Confirmed User
Industry Role:
Join Date: Aug 2005
Location: YUROP
Posts: 8,592
|
Quote:
One of my best performing site in search engines gets data from the API alone, so no local caching etc.
__________________
![]() Anal Webcams | Kinky Trans Cams Live | Hotwife XXX Tube | Get your Proxies here |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#36 | |
Bollocks
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
|
Quote:
I notice a distinct delay on my webcam page using API v2, of about 2 seconds or more - and I'm only getting a list of 40 cams. I want to eliminate this by going to a database driven approach, only trouble is my site is aimed more at UK and European visitors so those are the cams I pull out of the API, but my server is in the US. So that's not ideal.
__________________
Interserver unmanaged AMD Ryzen servers from $73.00 |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#37 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
First of all there are efficient ways to do things and inefficient ways. If someone has coded the api call and parse propely and is doing pagination then that could be a very fast site. However if they are doing just the api and trying to present all the cams all at once then it will probably be a slow load. On the server side solution, the database has to be designed properly and the sql calls need to be coded properly. Just because something is in a database does not mean it is fast or efficient. There is a lot of shitty code out there, I know because I have written some of it. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#38 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
I have not played with v2 on the server side so I am not sure what the best workaround would be yet. My gut instinct would be to hardcode my home ip in the client_ip field and use it that way but without playing with it some I could not give you a good answer. .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#39 |
Confirmed User
Join Date: Feb 2009
Posts: 201
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#40 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
That would appear to work. Thanks for that
![]() So, redwhiteandblue, there is your answer. .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#41 | |
Confirmed User
Industry Role:
Join Date: Aug 2005
Location: YUROP
Posts: 8,592
|
Quote:
__________________
![]() Anal Webcams | Kinky Trans Cams Live | Hotwife XXX Tube | Get your Proxies here |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#42 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
I thought you were talking about V1. But with V2, yeah, definitely can make a site run faster then going into a database or caching scheme. Less infrastructure to deal with. Less steps involved. I am going to set up dudefoxes using full client side javascript. Only call back to the server will be the click into the cams because I want to hit my tracking script (oh and the logo and crap like that). .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#43 |
Confirmed User
Industry Role:
Join Date: Aug 2005
Location: YUROP
Posts: 8,592
|
No-no, I'm talking about AWEs Video Promo API.. I havent checked CHBs API v2 yet
__________________
![]() Anal Webcams | Kinky Trans Cams Live | Hotwife XXX Tube | Get your Proxies here |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#44 |
Richest man in Babylon
Industry Role:
Join Date: Jan 2002
Location: Posts: 10,002
Posts: 5,678
|
@sarettah this is very cool and wicked fast.
How could chat_room_url_revshare and image_url be modified to reflect a white label URL without slowing it down? Otherwise adblock. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#45 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
You can modify the Chat room url ot pull from a whitelabel by just using: Whitelabel + Username So something like this (using my whitelabel at Hot Foxes at Camfoxes.net to link to): txt +='<a rel=nofollow style="color:#000000;font-weight:bold;" href=https://www.camfoxes.net/' + xmlDoc.getElementsByTagName("username")[i].childNodes[0].nodeValue + '>'; Where I was using the chat room url from the feed before. This appears to get past my adblockers and works on opera with ad blocking turnded on no problem: https://madspiders.com/demo/cb_apiv2_demo4.htm .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#46 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
Thanks .
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#47 |
Richest man in Babylon
Industry Role:
Join Date: Jan 2002
Location: Posts: 10,002
Posts: 5,678
|
Thanks Sarettah.
As a learning project I intend to use this to replace the WP Live Cam Wordpress theme I have running on a domain and it's huge Gigabyte size DB.... |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#48 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
I started in on 2 new sites yesterday using the pure javascript version.
Still have to do up some text and change up colors and shit but they are up and running. https://dudefoxes.com https://milffoxes.com Still have to doctor them up for mobile too. .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#49 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Figured out the pagination today. Works pretty slick.
.
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#50 |
Supermodel
Industry Role:
Join Date: Nov 2004
Location: Sodoma & Gomorra
Posts: 22,831
|
2 pages of cams
__________________
SMC Revenue - Best Tgirl websites of the world now VR ![]() Non exclusive BIG Tranny/shemale Package for sale, full 2257 - hit me up skype: nikkimontero ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |