I'm tring to use restsharp in F# to call the Mailgun API.
I modelled it on the sample C# code from Mailgun but I can't get it going.
The problem code is:
let client: RestClient =
new RestClient(
BaseUrl = Uri("https://api.mailgun.net/v3")
)
client.Authenticator = new HttpBasicAuthenticator("","")
This expression was expected to have type IAuthenticator' but here has type 'HttpBasicAuthenticator'
It seems that somehow the inherited type for one is different than the expected type which doesn't make sense to me. The HttpBasicAuthenticator object says it inherits from authentocatorBase
I haven't tested it, but most likely you have to cast the new object to the interface. F# requires it.
client.Authenticator = new HttpBasicAuthenticator("","") :> IAuthenticator
Have a look at https://fsharpforfunandprofit.com/posts/interfaces/
Related
I want to send email by connecting google via oauth
Below is the code present for C#
MailSender objMail = new MailSender();
objMail.TLS = true;
objMail.Username = "myaccount#gmail.com";
objMail.Password = "[oauth]ya29.Il-8B-88nf.......GhoNhUXKtBS-ZEQOAZ9tTWg";
...
objMail.Send();
For whole code please navigate to
https://www.aspemail.com/net_manual_03.html#3_5
To generate access token which is appended with "[oauth]" above, we are using
MailSender objMail = new MailSender();
MailSender objMail2 = objMail.GetAccessToken("GMAIL", "4/wQGBh....LtcM", false);
string AccessToken = objMail2.Username;
string RefreshToken = objMail2.Password;
int ExpiresIn = objMail2.Timeout;
I want to implement the same functionality in classic asp, but when i am creating object of "MailSender" in classic asp, it is throwing error that:
Object doesn't support this property or method:
'objMail.GetAccessToken'
Please suggest me how can i generate access token of oauth from classic asp
That error is telling you that the object you are using doesn’t recognise the method you are trying to call. In this situation the official documentation is the best resource.
Quote from GetAccessToken()
This method was introduced in version 5.5.0.1.
The likelihood here is you are using an older version of the ASPEmail COM component.
You can use the below code to output the version information;
<%
Dim Mail
Set Mail = Server.CreateObject("Persits.MailSender")
Call Response.Write("Version: " & Mail.Version)
%>
I'm using HtmlProvider to web scrape stock company news e.g. https://www.nasdaq.com/symbol/{STOCK_SYMBOL_HERE}/news-headlines but I'm getting an error in this line of code
let [<Literal>] stockNewsUrl = "https://www.nasdaq.com/symbol/AAPL/news-headlines"
let news = new HtmlProvider<stockNewsUrl>()
There is squiggle on the second line and the error was Error FS3033 The type provider 'ProviderImplementation.HtmlProvider' reported an error: Cannot read sample HTML from 'https://www.nasdaq.com/symbol/AAPL/news-headlines': The 'Value'='AAPL,technology' part of the cookie is invalid.
To make an HTTP request to https://www.nasdaq.com/symbol/AAPL/news-headlines, we are required to provide a CookieContainer. Since you are using the FSharp.Data library, I suggest to use its HTTP Utilities:
type Nasdaq = HtmlProvider<"/tmp.html">
let cc = CookieContainer ()
let data =
Http.RequestString ("https://www.nasdaq.com/symbol/AAPL/news-headlines", cookieContainer = cc)
|> Nasdaq.Parse
data.Tables.``Today's Market Activity``.Html
|> printfn "%A"
Of course you have to pre-download the page and save to /tmp.html first.
Small note: if we already have the HTML string (as in our case), we use Nasdaq.Parse; if we have a url, we use Nasdaq.Load.
It looks like this fails because F# Data sends cookies in a format that the Nasdaq service does not like. An easy workaround is to download the page once to have a sample available at compile-time and then download the page at runtime using some other means.
type Nasdaq = HtmlProvider<"c:/temp/nasdaq.html">
let wc = new WebClient()
let downloaded = wc.DownloadString("https://www.nasdaq.com/symbol/AAPL/news-headlines")
let ns = Nasdaq.Load(downloaded)
This works, but there are two issues:
The page dos not contain any tables/lists, so the ns value is not giving you nice static access to anything useful
I get timeout exception when I try to download the data using WebClient, so perhaps that also does not work (but it might just be that I'm behind a proxy or something..)
I have able to successfully connect and read emails using the 'python-o365' library:
Connection.oauth2('Client_ID','Client_Secret',store_token=True)
inbox = FluentInbox()
for message in inbox.fetch_next(2):
print(message.getSubject())
However, when I try to send an email using a more basic example, I am receiving a 401 response from the server.
Connection.oauth2('Client_ID','Client_Secret',store_token=True)
att = Attachment(path=FilePath)
m = Message()
m.setRecipients(EmailTo)
m.setSubject('DBM Errors Identified - ' + FileName)
m.setBody(MessageBody)
m.attachments.append(att)
m.sendMessage()
I have also tried setting the connection object and passing it through as a parameter:
auth = Connection.oauth2('Client_ID','Client_Secret',store_token=True)
m = Message(*auth=auth*)
That however results in an error message of:
TypeError: 'Connection' object is not callable
Thanks for the help!
I was able to bypass the issue by switching to a fork of the 'python-o365' library that I used above. I feel like I am probably missing something obvious with that library but this solved the problem
Here is the simplified version of the authentication flow that I have working in case it interests anyone:
scopes = ['https://graph.microsoft.com/Mail.Read'']
account = Account(('Client_Id', 'Client_Secret'], auth_method='oauth',scopes=scopes)
account.connection.get_authroization_url() #generate the url for user to authenticate
result_url = input('Paste the result URL once you have authenticated...')
account.connection.get_session() #generate a session
m = account.new_message()
m.to.add('EmailTo')
m.body = 'MessageText'
m.send()
I am using a doc data payments gateway service and when I try to give it a request to create an order it throws the following exception:
XmlSerializer attribute
System.Xml.Serialization.XmlAttributeAttribute is not valid in
version. Only XmlElement, XmlArray, XmlArrayItem, XmlAnyAttribute and
XmlAnyElement attributes are supported when IsWrapped is true.
I don't think it is an exception that has anything to do with the service. What am I doing wrong on my side of implementation. Can anyone help me with that?
EDIT
I have used DocDataPayments gateway and used the wsdl refrence they give to make the call.
The create call I am making is as follows:-
PaymentServiceSOAPClient client = new PaymentServiceSOAPClient();
createSuccess success = new createSuccess();
client.create(merchant, strMTID, paymentPreferences, menuPreferences, shopper, totalGrossAmount, billTo, "description", "Thanks for your purchase", true, new paymentRequest(), new invoice(), new technicalIntegrationInfo(), Convert.ToDecimal(0.9), out success);
I think, you are using wcf default serializer to make proxy classes.you can try with DataContract serializer instead default serializer.
In case of a system error from the GradesManagementService, the returned response object is null, but the response header includes the diagnostic information. What class do I use to get this information?
Here is my code:
GradesManagementServiceV10 port = service.getGradesManagementServiceV10();
GetGradeValuesByOrgUnitRequest r = new GetGradeValuesByOrgUnitRequest(); GetGradeValuesByOrgUnitResponse resp = new GetGradeValuesByOrgUnitResponse(); WSBindingProvider bp = (WSBindingProvider)port; bp.setOutboundHeaders( Headers.create(formatSOAPHeader())); ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, getUrl());
resp = port.getGradeValuesByOrgUnit(r); // the response is null. <------ How do I see what the error is?
In your service object (in the above code snippet that would be port, the object of the Web service proxy class GradesManagementServiceV10), ResponseHeader property would contain such information (this property's type is ResponseHeaderInfo).
If you are doing new development with Desire2Learn I would also suggest that you look at the Valence REST/JSON API. New features and new API calls are going to show up in that system http://docs.valence.desire2learn.com/ (it is always deployed, the docs are open, etc.)