I have error requests. I still don't know where to invoke request and how to fetch response. Where do I set API key?
var initialize = new Google.Apis.Services.BaseClientService.Initializer();
initialize.ApiKey = "key";
var speech = new Google.Apis.Speech.v1.SpeechService(new Google.Apis.Services.BaseClientService.Initializer {
});
var recognizeReq = new Google.Apis.Speech.v1.Data.RecognizeRequest();
var recognitionConf = new Google.Apis.Speech.v1.Data.RecognitionConfig();
recognitionConf.LanguageCode = "pl-PL";
recognitionConf.SampleRateHertz = 16000;
recognitionConf.Encoding = "FLAC";
recogniseReq.Config = recognitionConf;
var aud = new Google.Apis.Speech.v1.Data.RecognitionAudio();
string path1 = #"c:\output.flac";
//var bytesAudio = File.ReadAllBytes(path1);
aud.Uri = path1;
recognizeReq.Audio = aud;
var variable = speech.Speech.Recognize(recogniseReq);
variable.Key = "key";
//variable.OauthToken =
variable.Execute();
Google.Apis.Speech.v1.Data.RecognizeResponse resp = new Google.Apis.Speech.v1.Data.RecognizeResponse();
var lista = resp.Results;
I change software and now I use Google.Cloud.Speech.V1 library
I managed to save voice using NAudio
and I tried to send continuos request to cloud, but it doesn't work
'''
waveFile.Write(e.Buffer, 0, e.BytesRecorded);
waveFile.Flush();
audio5 = RecognitionAudio.FromBytes(e.Buffer);
var result = client.LongRunningRecognizeAsync(config, audio5);
'''
This solves problem.
problem with buffer is for a longer time.
I get into trap like others.
found solution in dispute about bug (from Google of corse ;) )
https://github.com/GoogleCloudPlatform/dotnet-docs-samples/blob/95b32e683ba534883b8a7f3c979deee101ba3678/speech/api/Recognize/InfiniteStreaming.cs
Related
I need to create automaion client for Azure webhook.
Following code is written by me to get AutomationManagementClient Value.
var cert = new X509Certificate2(Convert.FromBase64String(ConfigurationManager.AppSettings["CertBase64String"]));
var creds[![enter image description here][1]][1] = new CertificateCloudCredentials(ConfigurationManager.AppSettings["SubscriptionId"], cert);
AutomationManagementClient automationManagementClient = new AutomationManagementClient(creds);
I need that certificate string i.e. CertBase64String value as I don't know from where I will get that value.
Help me...
This error I am getting after updating as per your answer.
If you want to create the automation client, I suggest you try to use the ARM way to operate the automation. The following is the demo code works correctly on my side.
Prepare: Registry an AD application and assign role to applcation, more details please refer to Azure official tutorials. After that we can get tenantId, appId, secretKey from the Azure Portal.
We could use the following code to get the token
var tenantId = "tenantId";
var context = new AuthenticationContext($"https://login.windows.net/{tenantId}");
var clientId = "application Id";
var clientSecret = "client secret";
var resourceGroup = "resource group";
var automationAccount = "automationAccount";
var subscriptionId = "susbscriptionId";
var token = context.AcquireTokenAsync(
"https://management.azure.com/",
new ClientCredential(clientId, clientSecret)).Result.AccessToken;
if you use the Microsoft.Azure.Management.Automation Version <= 2.0.4 please try the following code.
var automationClient = new AutomationManagementClient(new TokenCloudCredentials(subscriptionId,token));
var webhook = automationClient.Webhooks.CreateOrUpdate(resourceGroup, automationAccount,new WebhookCreateOrUpdateParameters
{
Properties = new WebhookCreateOrUpdateProperties
{
ExpiryTime = DateTimeOffset.Now.AddDays(1),
IsEnabled = false,
Parameters = parameters,
Runbook = new RunbookAssociationProperty
{
Name = "xxxx"
},
Name = "xxxx",
Uri = "https://xxxx.xx"
}
});
if use the Microsoft.Azure.Management.Automation Version 3.0.0-preview, please try to the following case.
var automationClient = new AutomationClient(new TokenCredentials(token)) {SubscriptionId = subscriptionId};
var webhook = automationClient.Webhook.CreateOrUpdate(resourceGroup, automationAccount, "webhookName",
new WebhookCreateOrUpdateParameters
{
ExpiryTime = DateTime.Now.AddDays(1),
IsEnabled = false,
Parameters = parameters,
Name = "xxxxx",
Runbook = new RunbookAssociationProperty
{
Name = "xxxxx"
},
Uri = "https://xxx.xxx"
});
Update:
You could set the Parameters = null or if you have parameter, you could define the parameters as dictionary. Please also add the Name = "xxxx" in the code.
var parameters = new Dictionary<string, string> {{"test", "test"}};
var webhook = automationClient.Webhooks.CreateOrUpdate(resourceGroup, automationAccount,new WebhookCreateOrUpdateParameters
{
Properties = new WebhookCreateOrUpdateProperties
{
ExpiryTime = DateTimeOffset.Now.AddDays(1),
IsEnabled = false,
Parameters = parameters,
Runbook = new RunbookAssociationProperty
{
Name = "xxxx"
},
Name = "xxxx",
Uri = "https://xxxx.xx"
}
});
I test it on my side, it works correctly
"CertBase64String" will get by passing thumb-print of that certificate to following fucntion.
internal static X509Certificate2 GetCertificateFromthumbPrint(String certThumbPrint) {
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
//Find the certificate that matches the thumbprint.
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, certThumbPrint, false);
certStore.Close();
//Get the first cert with the thumbprint
X509Certificate2 cert = (certCollection.Count > 0) ? certCollection[0] : null;
return cert;
}
I have been working on google safe browsing API - I am sure I am doing everything correct but I get the error when I try to connect to the API
"Object reference not set to an instance of an object."
I have correct nuGet package installed
My code is the following
try
{
//cient_info
Google.Apis.Safebrowsing.v4.Data.ClientInfo client = new Google.Apis.Safebrowsing.v4.Data.ClientInfo();
client.ClientId = "testapp";
client.ClientVersion = "1";
//thread_info
Google.Apis.Safebrowsing.v4.Data.ThreatInfo threadInfo = new Google.Apis.Safebrowsing.v4.Data.ThreatInfo();
threadInfo.ThreatTypes.Add("MALWARE");
threadInfo.ThreatTypes.Add("SOCIAL_ENGINEERING");
threadInfo.PlatformTypes.Add("WINDOWS");
threadInfo.ThreatEntryTypes.Add("URL");
//url to check
Google.Apis.Safebrowsing.v4.Data.ThreatEntry ITEM = new Google.Apis.Safebrowsing.v4.Data.ThreatEntry();
ITEM.Url = "http://www.google.com.au/";
threadInfo.ThreatEntries.Add(ITEM);
//API Call
var googleClient = new WebClient();
var response = googleClient.DownloadString("https://safebrowsing.googleapis.com/v4/" + client + threadInfo + "&key=myapikey");
var releases = JObject.Parse(response);
return releases.ToString();
}
catch (Exception X)
{
var Error = X.Message;
return Error.ToString();
}
I think i am messing up at var response = googleClient.DownloadString but I am not sure what is the correct call method for this.
Does anyone have any idea?
Cheers
I used ThreatMatches.Find() and it worked.
ThreatMatchesResource.FindRequest request = service.ThreatMatches.Find(
new FindThreatMatchesRequest{Client = client, ThreatInfo = threatInfo});
FindThreatMatchesResponse execute = await request.ExecuteAsync();
var releases = execute.ToString();
You need to put your api key in
googleClient.DownloadString("https://safebrowsing.googleapis.com/v4/" + client + threadInfo + "&key=myapikey");
I feel like I am going insane trying to get the most simple of things to work! I have a mailing list in Google Spreadsheet on Google Drive. I have created a user interface that prompts for the message that the user wants to include in the email. My code looks like this.
function startBulkEmailUI(e) {
//create main form
var app = UiApp.createApplication().setTitle('Send Email').setWidth(602).setHeight(402);
var scrollPanel = app.createScrollPanel().setId('scrollPanel').setAlwaysShowScrollBars(true) ;
var mainPanel = app.createVerticalPanel().setId('mainPanel');
mainPanel.setStyleAttribute('border', '1px solid #C0C0C0').setWidth("100%").setHeight("100%");
scrollPanel.add(mainPanel);
//create panel for input boxes etc
var inputPanel = app.createVerticalPanel().setId('inputPanel').setWidth("100%").setHeight("100%").setSpacing(0);
var messageLabel = app.createLabel('E-mail Message');
var messageBox = app.createTextArea().setName('messageBox').setId('messageBox').setVisible(true).setWidth(400).setHeight(150);
var attachmentLabel = app.createLabel('E-mail Attachment');
var attachmentCheckBox = app.createCheckBox('Attach a file').setValue(false);
inputPanel.add(messageLabel).add(messageBox).add(attachmentLabel).add(attachmentCheckBox);
mainPanel.add(inputPanel).setCellHorizontalAlignment(inputPanel, UiApp.HorizontalAlignment.CENTER) ;
inputPanel.setCellHorizontalAlignment(messageLabel, UiApp.HorizontalAlignment.CENTER);
inputPanel.setCellHorizontalAlignment(messageBox, UiApp.HorizontalAlignment.CENTER);
inputPanel.setCellHorizontalAlignment(attachmentLabel, UiApp.HorizontalAlignment.CENTER);
inputPanel.setCellHorizontalAlignment(attachmentCheckBox, UiApp.HorizontalAlignment.CENTER);
//add function buttons
var buttonsPanel = app.createHorizontalPanel().setStyleAttribute('margin', '20px').setWidth(500);
var closeButton = app.createButton('Close',app.createServerHandler('close_'));
var sendButton = app.createButton('Send!').setId("sendButton");
buttonsPanel.setId('buttonsPanel').add(closeButton).add(sendButton);
mainPanel.add(buttonsPanel).setCellHorizontalAlignment(buttonsPanel, UiApp.HorizontalAlignment.CENTER);
buttonsPanel.setCellHorizontalAlignment(closeButton, UiApp.HorizontalAlignment.CENTER).setCellHorizontalAlignment(sendButton, UiApp.HorizontalAlignment.CENTER);
app.add(scrollPanel);
//handlers
var handlerSendEmails = app.createServerClickHandler('sendEmails');
handlerSendEmails.addCallbackElement(inputPanel);
sendButton.addClickHandler(handlerSendEmails);
//show the form
ss.show(app);
return app;
}
function sendEmails(e) {
var contactDetail = getContactDetail();
var count = 0;
var failed = 0;
for (i in contactDetail) {
var row = contactDetail[i];
var emailAddress = row[9];
var stuff = e.parameter.messageBox.value;
Logger.log(e.parameter);
var message = 'Hi, ' + row[4] + '\n\n' + 'This is a test!'; // Second column
var subject = 'Test Email';
try {
// MailApp.sendEmail(emailAddress, subject, message);
count = count+1;
} catch(e) {
failed = failed+1;
}
}
var msg = stuff;
Browser.msgBox('Debug Msg', msg, Browser.Buttons.OK);
}
I want the user to enter information into the textarea, which I can then use as the body of an email. I discovered there is no getText, so I have found hundreds of answer saying it should look like the code above: you create a callbackhandler, then use e.parameter.OBJECT_NAME.value to get the text. It simply does not work for me and I have tried every workaround that I can think of. Any suggestions? Is my code faulty (I know it's messy...)?
The "normal" way to get a widget's value in a handler function is in the form e.parameter.widgetName so in you case you should simply use
var stuff = e.parameter.messageBox; without the ".value" , the result is a string.
The code seems to run. I don't get any error messages, but an invoice does not appear in QB after I sync. The code is basically this (http://pastebin.com/y7QENxeX) with a few (presumably) minor changes as noted. I'm able to create Accounts and Customers so I believe the basic infrastructure of my app is good. I don't understand why I'm stuck on invoices. I think my customerID is 2. I only have 5 in my company right now. And I think my itemID is 1 as I only have one in QB right now.
Any and all help is greatly appreciated.
Intuit.Ipp.Data.Qbd.PhysicalAddress physicalAddress = new Intuit.Ipp.Data.Qbd.PhysicalAddress();
physicalAddress.Line1 = "123 Main St.";
physicalAddress.Line2 = "Apt. 12";
physicalAddress.City = "Mountain View";
physicalAddress.CountrySubDivisionCode = "CA";
physicalAddress.Country = "USA";
physicalAddress.PostalCode = "94043";
physicalAddress.Tag = new string[] { "Billing" };
Intuit.Ipp.Data.Qbd.InvoiceHeader invoiceHeader = new Intuit.Ipp.Data.Qbd.InvoiceHeader();
invoiceHeader.ARAccountId = new Intuit.Ipp.Data.Qbd.IdType() { idDomain = Intuit.Ipp.Data.Qbd.idDomainEnum.QB, Value = "37" };
invoiceHeader.ARAccountName = "Accounts Receivable";
// original code : invoiceHeader.CustomerId = new IdType() { idDomain = idDomainEnum.NG, Value = "3291253" };
invoiceHeader.CustomerId = new Intuit.Ipp.Data.Qbd.IdType() { idDomain = Intuit.Ipp.Data.Qbd.idDomainEnum.QB, Value = "2" };
invoiceHeader.Balance = (decimal)100.00;
invoiceHeader.BillAddr = physicalAddress;
invoiceHeader.BillEmail = "detroit#tigers.com";
invoiceHeader.CustomerName = "Detroit Tigers";
invoiceHeader.DocNumber = "1234567";
invoiceHeader.DueDate = DateTime.Now;
invoiceHeader.ShipAddr = physicalAddress;
invoiceHeader.ShipDate = DateTime.Now;
invoiceHeader.TaxAmt = (decimal)5;
invoiceHeader.TaxRate = (decimal).05;
invoiceHeader.ToBeEmailed = false;
invoiceHeader.TotalAmt = (decimal)105.00;
List<Intuit.Ipp.Data.Qbd.InvoiceLine> listLine = new List<Intuit.Ipp.Data.Qbd.InvoiceLine>();
//Loop for multiple invoice lines could be added here
Intuit.Ipp.Data.Qbd.ItemsChoiceType2[] invoiceItemAttributes = { Intuit.Ipp.Data.Qbd.ItemsChoiceType2.ItemId, Intuit.Ipp.Data.Qbd.ItemsChoiceType2.UnitPrice, Intuit.Ipp.Data.Qbd.ItemsChoiceType2.Qty };
// original code : object[] invoiceItemValues = { new IdType() { idDomain = idDomainEnum.QB, Value = "5" }, new decimal(33), new decimal(2) };
object[] invoiceItemValues = { new Intuit.Ipp.Data.Qbd.IdType() { idDomain = Intuit.Ipp.Data.Qbd.idDomainEnum.QB, Value = "1" }, new decimal(33), new decimal(2) };
var invoiceLine = new Intuit.Ipp.Data.Qbd.InvoiceLine();
invoiceLine.Amount = 66;
invoiceLine.AmountSpecified = true;
invoiceLine.Desc = "test " + DateTime.Now.ToShortDateString();
invoiceLine.ItemsElementName = invoiceItemAttributes;
invoiceLine.Items = invoiceItemValues;
invoiceLine.ServiceDate = DateTime.Now;
invoiceLine.ServiceDateSpecified = true;
listLine.Add(invoiceLine);
Intuit.Ipp.Data.Qbd.Invoice invoice = new Intuit.Ipp.Data.Qbd.Invoice();
invoice.Header = invoiceHeader;
invoice.Line = listLine.ToArray();
Intuit.Ipp.Data.Qbd.Invoice addedInvoice = commonService.Add(invoice);
Chris
You need to read the following information about how QuickBooks for Windows Sync Manager works, how to see if Sync ran correctly, if objects are in an errored state and how to resolve. It could be any number of things. Once a record is inserted into the cloud, it asynchronously downloads to QuickBooks on the desktop, at which time business logic is applied and records are matched from the cloud to the desktop. If there is an issue, sync manager will show a record of the object that failed, why it failed and the object will now be in an error state.
At this point you can review the error and take steps to fix, like revert or update and resubmit. Links to the documentation below.
QuickBooks Sync Manager
Data Sync
Objects in Errored State
Sync Activity
Sync Status
regards
Jarred
I'm trying to send some XML to a rails app in Flex. I'm using the URLRequest and URLLoader objects. However, I'm having trouble determining how to send the XML and _method parameter to the rails app using these flash objects. Below is how I'm currently trying to achieve this.
var request:URLRequest = new URLRequest();
request.method = URLRequestMethod.POST;
request.data = new Object();
request.data.xml = Blog.xml.toXMLString();
request.contentType = "text/xml";
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, saveCompleteHandler);
var saveUrl:String = "";
saveUrl = BASE_URL;
if (Blog.isNewBlog)
{
// Set the rails REST method.
request.data._method = "POST";
saveUrl += "blogs.xml";
}
else
{
// Set the rails REST method.
request.data._method = "PUT";
saveUrl += "blogs/" + Blog.id.toString() + ".xml";
}
request.url = saveUrl;
//trace(request.data.toString());
loader.load(request);
However the only data that is getting sent to the server is [Object object]. If some one could let me know where I'm going wrong I'd greatly appreciate it. Thanks.
You probably want to use a URLVariables object for request.data.
var request:URLRequest = new URLRequest();
request.data = new URLVariables();
request.data.xml = Blog.xml.toXMLString();
...
When the data is serialized, I think it will be in the format you're expecting. I'm basing this off of the API description for URLRequest.data.
Old post, but may be useful: besides
request.data.xml = Blog.xml.toXMLString();
you can also do
request.data['xml'] = Blog.xml.toXMLString();