[SOLVED] Ubidots library c# Visual Studio 2017

I’m using the ubidots library


with Visual studio 2017
Since I need to read both the value of my entry and the date in the ubidots database I had this problem:

int asd = ExampleValues [x] .GetValue (); //works well
while

long Time = ExampleValues [0] .GetTimestamp (); //it does not work
and visual from error

  • $ exception {“Specified cast invalid.”} System.InvalidCastException

where am I wrong?

there is another way to read the DATETIME of the recording of that data (x) on ubidots
Thanks in advance

Hi there, our C# library is actually outdated and because of this you may get these kind of errors. My advice is to create your own HTTP that fits our REST API, below you may find a very simple example to retrieve data from one variable in an Ubidots account:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Request library
using System.Net;
using System.IO;

					
public class Program
{
	public static void Main()
	{
		string html = string.Empty;
		string url = @"https://industrial.api.ubidots.com/api/v1.6/devices/demo/demo?token=YOUR_TOKEN_HERE";

		HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
		request.AutomaticDecompression = DecompressionMethods.GZip;

		using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
		using (Stream stream = response.GetResponseStream())
		using (StreamReader reader = new StreamReader(stream))
		{
			html = reader.ReadToEnd();
		}

		Console.WriteLine(html);
	}
}

All the best