Posts: 111
Threads: 31
Joined: Apr 2007
is it possible with qm to access the textnow api at api.textnow.me?
python example:
https://github.com/bn0x/textnow/blob/mas...Request.py
Posts: 12,092
Threads: 142
Joined: Dec 2002
Should be possible, but it's difficult for me to convert this, for example I don't know what is signature.generate(), and I cannot find documentation or more examples. A C# example would be easier to understand and convert.
Posts: 111
Threads: 31
Joined: Apr 2007
Posts: 12,092
Threads: 142
Joined: Dec 2002
C# can be used in QM like this:
Macro
textnow C#
str R=CsFunc("" "100" "test")
out R
#ret
//C# code
using System;
using System.Net;
using System.Text;
using System.IO;
public class Test
{
public static string TestFunction(string pnum, string msg)
{
;;;;;;;;HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri("https://www.textnow.com/api/users/[redacted username]/messages"));
;;;;;;;;HttpWebResponse response = null;
;;;;;;;;NetworkCredential netCredential =
;;;;new NetworkCredential("[redacted username]", "[redacted password]");
;;;;;;;;req.Credentials = netCredential;
;;;;;;;;req.PreAuthenticate = true;
req.Headers.Add("Access-Control-Request-Headers","accept, origin, x_session, content-type");
req.Headers.Add("Access-Control-Request-Method","POST");
;;;;;;;;req.Method = "GET";
;;;;;;;;response = (HttpWebResponse)req.GetResponse(); //error occurs here <<<<<<<<<<<
;;;;;;;;req.Method = "POST";
;;;;;;;;req.ContentType = "application/x-www-form-urlencoded";
;;;;;;;;req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
;;;;;;;;req.Referer = "https://www.textnow.com/api/users/[redacted username]/messages";
;;;;;;;;req.AllowAutoRedirect = true;
;;;;;;;;req.KeepAlive = true;
;;;;;;;;req.ContentType = "application/json";
;;;;;;;;StringBuilder postData = new StringBuilder();
;;;;;;;;postData.Append("%7B%22contact_value%22%3A%22" + pnum + "%22%2C");
;;;;;;;;postData.Append("%22contact_type%22%3A2%2C");
;;;;;;;;postData.Append("%22message%22%3A%22" + msg + "%22%2C");
;;;;;;;;postData.Append("%22read%22%3A1%2C");
;;;;;;;;postData.Append("%22message_direction%22%3A2%2C");
;;;;;;;;postData.Append("%22message_type%22%3A1%2C");
;;;;;;;;postData.Append("%22date%22%3A%22Sat+Nov+30+2013+13%3A20%3A44+GMT-0800+(Pacific+Standard+Time)%22%2C");
;;;;;;;;postData.Append("%22from_name%22%3A%22[Redacted]%22%7D");
;;;;;;;;StreamWriter sw = new StreamWriter(req.GetRequestStream());
;;;;;;;;sw.Write(postData.ToString());
;;;;;;;;response = (HttpWebResponse)req.GetResponse();
,return "returned";
}
//add private functions here if need
}
Another way:
Macro
Macro5
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest r._create
r.Open("GET" "https://www.textnow.com/api/users/[redacted username]/messages")
r.SetCredentials("[redacted username]", "[redacted password]")
;req.PreAuthenticate = true; //?
r.SetRequestHeader("Access-Control-Request-Headers","accept, origin, x_session, content-type")
r.SetRequestHeader("Access-Control-Request-Method","POST")
r.Send()
;;...
Posts: 111
Threads: 31
Joined: Apr 2007
Hmmm..with first way I am getting following error
Error (RT) in <open ":1: /4">Macro1: 0x80131500,
The remote server returned an error: (401) Unauthorized.
at Test.TestFunction(String pnum, String msg). <help #IDP_ERR>?
Second way I get this error:
Error in <open ":1431: /175">Macro2: Expected 3 arguments, not 2.
Which I can fix, because line 4 SetCredentials needs a flag (0).
But when I fix, macro does nothing. Can we make it output results?
Posts: 1,338
Threads: 61
Joined: Jul 2006
second example needs a flag argument as 3rd parameter in SetCredentials function
see msdn
https://docs.microsoft.com/en-us/windows...redentials
most likely this
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
Posts: 111
Threads: 31
Joined: Apr 2007
Yes, I figured that out. The flags are 0 or 1.
Do you know how to get result to output?
Posts: 1,338
Threads: 61
Joined: Jul 2006
07-20-2018, 06:04 AM
(This post was last modified: 07-20-2018, 06:14 AM by Kevin.)
should give ya enough info hopefully
out r.GetAllResponseHeaders
out "---------------------------------"
out r.ResponseText
out r.StatusText
out r.Status
Posts: 111
Threads: 31
Joined: Apr 2007
Posts: 1,338
Threads: 61
Joined: Jul 2006
Posts: 111
Threads: 31
Joined: Apr 2007
It did, but I cannot figure out the authentication.
{"error_code":"AUTHENTICATION_FAILED"}
Unauthorized
401
Posts: 1,338
Threads: 61
Joined: Jul 2006
07-21-2018, 09:19 PM
(This post was last modified: 07-22-2018, 07:11 AM by Kevin.)
Ya from what i can tell the textnow api is json based. If you have npm (node.js) their is a working api for it. Check it out here
https://www.npmjs.com/package/textnow-api
Can even test it on that page as well
Posts: 111
Threads: 31
Joined: Apr 2007
I had looked at that previously but I do not know json thanks though
Posts: 726
Threads: 99
Joined: Mar 2018
@kevin
How to add a body ?
http://www.quickmacros.com/forum/showthr...2#pid33492
Macro
Macro2
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest r._create
r.Open("POST" F"https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic")
r.setRequestHeader("content-type", "application/x-www-form-urlencoded")
;code: body
r.Send
out r.GetAllResponseHeaders
out "---------------------------------"
out r.ResponseText
out r.StatusText
out r.Status