Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   General Business Knowledge (http://www.greenguysboard.com/board/forumdisplay.php?f=10)
-   -   Tech Cams - Chaturbate API V2 parsing via JavaScript (http://www.greenguysboard.com/board/showthread.php?t=72106)

sarettah 2021-03-12 09:18 AM

Tech Cams - Chaturbate API V2 parsing via JavaScript
 
Good morning Greenguys denizens. First, I would like to apologize for sometimes forgetting to come visit and post over here. No excuse, shit happens.

I was trying to think of what I could post that would be helpful to folks over here. I decided to post something that I posted at the Zoo about a month ago. For those of you who still visit the Zoo, you will have seen this before. For those that no longer make it over there, I hope this is helpful to you.

---------------------------------------------------------------------------

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
  // 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


// OR
//Pulling the xml page via a jquery AJAX call





.

sarettah 2021-03-12 09:19 AM

Example 1 - Using Javascript for the ajax api call:

https://madspiders.com/demo/cb_apiv2_demo1.php

Example 1 source code:

Code:

  // 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;
  }
?>


       

Example of pulling CB API Version 2





Example of pulling Chaturbate API Version 2 using pure javascript











sarettah 2021-03-12 09:19 AM

Example 2: Using jquery for the ajax api call:

https://madspiders.com/demo/cb_apiv2_demo2.php

Example 2 source code:

Code:

  // 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;
  }
?>


       

Example of pulling CB API Version 2







Example of pulling Chaturbate API Version 2 using javascript and AJAX












sarettah 2021-03-12 09:23 AM

Narrator comment:

In the ooriginal Zoo thread, Kitt from Chaturbate posted a comment to me that is quite pertyinent so I will quote it here:

Quote:

Originally Posted by CB Kitt (Post 22821270)
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.

Thanks for that. I will make a note of it.

Here is the link for the docs

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/
[/quote]

sarettah 2021-03-12 09:25 AM

Sample using just javascript - no php. Using request_ip in the client_ip parameter.

https://madspiders.com/demo/cb_apiv2_demo3.htm

Source:
Code:






       

Example of pulling CB API Version 2






Example of pulling Chaturbate API Version 2 using just javascript












sarettah 2021-03-12 09:27 AM

Narrator comment: After I had posted the samples, a friend told me some stuff:

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']);
  }

He also reminded me to always escape the server vars as a security step.

So I am changing up the 2 php demos to utilize this methodology.


Thanks to K0nr4d for the advice. https://www.mechbunny.com/ is Konr4d's baby if you did not know that already.


.

sarettah 2021-03-12 09:28 AM

https://madspiders.com/demo/cb_apiv2_demo1.php

Demo 1 new source code:

Code:

  // 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;
  }
?>



       

Example of pulling CB API Version 2





Example of pulling Chaturbate API Version 2 using pure javascript










.

sarettah 2021-03-12 09:28 AM

https://madspiders.com/demo/cb_apiv2_demo2.php

Demo 2 new source code:

Code:

  // 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;
  }
?>



       

Example of pulling CB API Version 2







Example of pulling Chaturbate API Version 2 using javascript and AJAX











.

sarettah 2021-03-12 09:31 AM

I did up 2 live sites using the pure javascript version.

https://dudefoxes.com

https://milffoxes.com

Feel free to look under the sheets.

That's all I have for now. I hope some of you find this useful.

I will try to be more active on the board going forward but I will not promise anything. I believe that I have said that before, probably multiple times on multiple boards.

.

JustRobert 2021-03-12 10:07 AM

Thanks for putting all that in.

I keep saying I'm going to try doing this but get lazy and just slap the iframe where I want it.

If I finally get around to it I know this is here |thumb

sarettah 2021-03-12 07:55 PM

Quote:

Originally Posted by JustRobert (Post 563566)
Thanks for putting all that in.

I keep saying I'm going to try doing this but get lazy and just slap the iframe where I want it.

If I finally get around to it I know this is here |thumb

You are quite welcome.

Easy to use it to make a little widget of 3 or 4 or 10 cams.

.

Greenguy 2021-03-13 05:34 AM

Quote:

Originally Posted by sarettah (Post 563556)
Good morning Greenguys denizens. First, I would like to apologize for sometimes forgetting to come visit and post over here. No excuse, shit happens.

1 - All 5 of us accept your apology :D

2 - DAMN! THANK YOU!!!

JAI-LING 2021-03-13 09:55 AM

Really useful stuff.

We must be using the old API. Is that why monthly checks have gone to...still waiting after 3 months of next to no sales?

sarettah 2021-03-14 12:27 AM

Quote:

Originally Posted by JAI-LING (Post 563578)
Really useful stuff.

We must be using the old API. Is that why monthly checks have gone to...still waiting after 3 months of next to no sales?

V1 API still works fine. I had asked Chaturbate about when they planned end of life for it and they said that there is no plan to shut it down.

Most of my sites still run the old API.

.

JAI-LING 2021-03-15 08:06 AM

Quote:

Originally Posted by sarettah (Post 563580)
V1 API still works fine. I had asked Chaturbate about when they planned end of life for it and they said that there is no plan to shut it down.

Most of my sites still run the old API.

.

Any idea why sales are sucking? Not trolling here just we were doing okay with CB, monthly to bi-weekly payments on a regular basis. Now we have not hit the minimum for almost 3 months.

A lot of people are talking about it. Models overlays are an issue for one. What else? Models inviting people to sign up again is another. We've reported a few to CB.

sarettah 2021-03-15 08:58 PM

Quote:

Originally Posted by JAI-LING (Post 563587)
Any idea why sales are sucking? Not trolling here just we were doing okay with CB, monthly to bi-weekly payments on a regular basis. Now we have not hit the minimum for almost 3 months.

A lot of people are talking about it. Models overlays are an issue for one. What else? Models inviting people to sign up again is another. We've reported a few to CB.

My signups have been in the dumps but my traffic and sales have been steady. I think it is getting harder to find traffic that does not already have a cookie set. Lots of cookie stuffing going on I think.

I know that a lot of people have been saying that their numbers are down and I really cannot offer any real enlightenment on the issue.

I do know that my traffic is mostly from google and the biggest effect on how well I do in sign ups is the positions I have in G. If I am getting lots of keywords in the 1-3 positions then I get lots of signups. If I drop down to the 4-5 position my signups are half what they are from 1-3. Move down the page and same thing, positions 6-7 are about half of what I get from positions 4-5. If I am only showing up on page 2 then I get nothing in signups.

Right now, for Camfoxes I move between position 2 and 5 for Free Adult webcams quite a bit. When I am in position 2, things rock, when I am in position 4 I don't get shit.

So, I put blame for any problems I have on google and cookie stuffing.

.

JustRobert 2021-03-16 10:48 AM

Quote:

Originally Posted by JAI-LING (Post 563587)
Any idea why sales are sucking?

Not sure if this has anything to do with it but...

I spent some time yesterday actually looking at cams which I did months ago, to get some ideas of what really goes on for sales text purposes, and really noticed a significant jump in links/watermarks to their OnlyFans.

Wondering if members are finding it cheaper for them to buy a month pass at OF for their videos then purchasing a bunch of individual clips at CB.

sarettah 2021-03-16 02:18 PM

Quote:

Originally Posted by JustRobert (Post 563603)
Not sure if this has anything to do with it but...

I spent some time yesterday actually looking at cams which I did months ago, to get some ideas of what really goes on for sales text purposes, and really noticed a significant jump in links/watermarks to their OnlyFans.

Wondering if members are finding it cheaper for them to buy a month pass at OF for their videos then purchasing a bunch of individual clips at CB.

I would think that true cams fans would not be the perfect customer for clips.

But I could be wrong, I often am.

.

JAI-LING 2021-03-22 02:37 PM

Quote:

Originally Posted by JustRobert (Post 563603)
Not sure if this has anything to do with it but...

I spent some time yesterday actually looking at cams which I did months ago, to get some ideas of what really goes on for sales text purposes, and really noticed a significant jump in links/watermarks to their OnlyFans.

Wondering if members are finding it cheaper for them to buy a month pass at OF for their videos then purchasing a bunch of individual clips at CB.

Thats a very possible answer. CB should ban external links maybe.
I've noticed the jump in onlyfans links on CB and nothing is done to remove them.

JAI-LING 2021-03-22 02:39 PM

Quote:

Originally Posted by sarettah (Post 563594)
My signups have been in the dumps but my traffic and sales have been steady. I think it is getting harder to find traffic that does not already have a cookie set. Lots of cookie stuffing going on I think.

I know that a lot of people have been saying that their numbers are down and I really cannot offer any real enlightenment on the issue.

I do know that my traffic is mostly from google and the biggest effect on how well I do in sign ups is the positions I have in G. If I am getting lots of keywords in the 1-3 positions then I get lots of signups. If I drop down to the 4-5 position my signups are half what they are from 1-3. Move down the page and same thing, positions 6-7 are about half of what I get from positions 4-5. If I am only showing up on page 2 then I get nothing in signups.

Right now, for Camfoxes I move between position 2 and 5 for Free Adult webcams quite a bit. When I am in position 2, things rock, when I am in position 4 I don't get shit.

So, I put blame for any problems I have on google and cookie stuffing.

.

Likely suspects. Google and stuffing. Sites can do something about stuffing right? Maybe not.

sarettah 2021-03-22 03:42 PM

Quote:

Originally Posted by JAI-LING (Post 563656)
Thats a very possible answer. CB should ban external links maybe.
I've noticed the jump in onlyfans links on CB and nothing is done to remove them.

One of the reasons that Chaturbate is so popular with models is that Chaturbate allows them to promote other sites like onlyfans. CB is pretty liberal with allowing the models to do a lot of things that other sites don't.

Makes Chaturbate appear very model friendly.

just imho of course.

.

sarettah 2021-03-22 03:43 PM

Quote:

Originally Posted by JAI-LING (Post 563657)
Likely suspects. Google and stuffing. Sites can do something about stuffing right? Maybe not.

I am not sure what can be done about cookie stuffing so I have concerned myself more with figuring out the best methods of cookie stuffing ;p

I have not been very successful :(

.

JAI-LING 2021-03-28 11:39 AM

The polite way for models to behave...

If you have not registered as a member of FCX or have
never purchased points,
please register from the URL below.
https://is.gd/pW4xce

sarettah 2021-04-05 10:44 AM

Quote:

Originally Posted by JAI-LING (Post 563711)
The polite way for models to behave...

If you have not registered as a member of FCX or have
never purchased points,
please register from the URL below.
https://is.gd/pW4xce

A lot of that going around.

.

JAI-LING 2021-04-06 09:14 AM

Yeah.

Its a tough call for me. Webmasters like cam models have families. We all need to eat. But some of the cams girls are so oblivious or they are such assholes... Its not a good way to develop a career. of course on the other hand, don't get me started about webmasters.

Thanks, Sarettah for your thoughtful posts. Its good to see here.


All times are GMT -4. The time now is 10:59 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc