Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var user_api_key = "YOUR_USER_API_KEY";
  2. var channel_id = 123456; // fallback channel ID
  3. var read_api_key = 'YOUR_CHANNEL_READ_API_KEY';
  4. if (window.parent) {
  5.     var channel_id = window.parent.channel.channel.id;
  6.     $.ajax({
  7.         url: "https://api.thingspeak.com/channels.json",
  8.         dataType: 'json',
  9.         async: false,
  10.         data: { 'api_key': user_api_key },
  11.         success: function(data) {
  12.             if (data) {
  13.                 $.each( data, function( key, channel ) {
  14.                     if (channel.id == channel_id) {
  15.                         $.each( channel.api_keys, function( key, api_key_data ) {
  16.                             if (api_key_data.write_flag == false) {
  17.                                 read_api_key = api_key_data.api_key;
  18.                                 return false; // break out of loop
  19.                             }
  20.                         });
  21.                     }
  22.                 });
  23.             }
  24.         }
  25.     });
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement