Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
textnow api
#1
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
#2
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.
#3
How does this work?

https://stackoverflow.com/questions/2031...b-response
#4
C# can be used in QM like this:

Macro textnow C#
Code:
Copy      Help
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
Code:
Copy      Help
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()

;;...
#5
Hmmm..with first way I am getting following error

Code:
Copy      Help
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:

Code:
Copy      Help
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?
#6
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
#7
Yes, I figured that out. The flags are 0 or 1.

Do you know how to get result to output?
#8
should give ya enough info hopefully
Code:
Copy      Help
out r.GetAllResponseHeaders
out "---------------------------------"
out r.ResponseText
out r.StatusText
out r.Status
#9
Thank you Kevin
#10
did you get it working?
#11
It did, but I cannot figure out the authentication.

Code:
Copy      Help
{"error_code":"AUTHENTICATION_FAILED"}
Unauthorized
401
#12
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
#13
I had looked at that previously but I do not know json thanks though
#14
@kevin

How to add a body ?

http://www.quickmacros.com/forum/showthr...2#pid33492


Macro Macro2
Code:
Copy      Help
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


Forum Jump:


Users browsing this thread: 1 Guest(s)