View Single Post
Old 2021-03-12, 09:19 AM   #2
sarettah
Asleep at the switch? I wasn't asleep, I was drunk
 
Join Date: Apr 2005
Posts: 214
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>
<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>
sarettah is offline   Reply With Quote