Matlab webread with google translation api - matlab

I have the same problem when i called Google translation API, this is my code
url = 'https://translation.googleapis.com/language/translate/v2'
Options.ContentType ='Josn';
options.KeyValue='XXXXXX';
response = webread(url,options)
`options.KeyName = 'apikey';
the following error appeared :
Error using readContentFromWebService (line 37) The server returned the message: "Forbidden" for URL, 'https://translation.googleapis.com/language/translate/v2' (with HTTP response code 403).
Error in webread (line 115) [varargout{1:nargout}] = readContentFromWebService(connection, options);
I filled key value as it is in my console, any one help?

Related

infobip chatbot fetching data

TypeError: invokeMember (get) on com.infobip.bot.engine.anticorruption.external.coding.execution.CodingAttributeApi#5c7c1bc1 failed due to: Arity error - expected: 1 actual: 2
found a error while fetching data from api.
i hit a api got back the response code 200.
data was not getting set in a infobip variable .
let list = attributeApi.get('getavailablity');
attributeApi.set('departure_time',list[8-1].dT );
attributeApi.get('return_time', list[8-1].aT);
attributeApi.set('total_amount', list[8-1].totalAmount);
Just change:
attributeApi.get('return_time', list[8-1].aT);
to:
attributeApi.set('return_time', list[8-1].aT);

Sending data to Firebase from Matlab

I want to save data to firebase from Matlab. Does firebase have similar api calls like ThingSpeak? How can i send JSON data from matlab by making API calls?
I am making API calls from Matlab like for JSON:
Firebase_Url = 'https://ecgproject-86945.firebaseio.com/';
writeApiKey = '***';
data = ['api_key=',writeApiKey,'&name=',"JSOpn9ZC54A4P4RoqVa"];
response = webwrite(Firebase_Url,data)
%data = struct('api_key',writeApiKey,'field1',data); //also tries this
%options = weboptions('MediaType','application/json');
The Error:
Error using readContentFromWebService (line 46)
The server returned the status 405 with message "Method Not Allowed" in response to the
request to URL https://ecgproject-86945.firebaseio.com/.
Error in webwrite (line 139)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in Untitled (line 16)
response = webwrite(Firebase_Url,data)
From reading the mathworks documentation on webwrite you need to use the two-parameter version of the method, passing in the additional information inside the second, data object:
data = ['api_key=',writeApiKey,'&name=',"JSOpn9ZC54A4P4RoqVa"];
response = webwrite(FirebaseURL,data)
Okay I found the solution apparently i didn't add .json at the end of the URL. Thank You. Here is the solution:
Firebase_Url = 'https://***.firebaseio.com/Channel1.json';
response = webwrite(Firebase_Url,'{ "first": "Jack", "last": "Sparrow" }')

Google URL Shortener API - Getting started

I'm trying to run the sample from Google's API sample here in Script.google.com.
Sample Code:
function getClicks(shortUrl) {
var url = UrlShortener.Url.get(shortUrl, {
projection: 'ANALYTICS_CLICKS'
});
Logger.log('The URL received %s clicks this week.', url.analytics.week.shortUrlClicks);
}
Error:
Required parameter: shortUrl (line 2, file "Code")
What am I missing?

Azure encoding job via REST Fails

I am trying to upload a video and encode it via azure rest service.
I have now hit the step of encoding the video but I am having difficulties with the request.
The following code shows my request:
var joburl = res.RequestMessage.RequestUri + "Jobs";
client = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
client.DefaultRequestHeaders.Add("x-ms-version", "2.8");
client.DefaultRequestHeaders.Add("DataServiceVersion", "3.0");
client.DefaultRequestHeaders.Add("MaxDataServiceVersion", "3.0");
client.DefaultRequestHeaders.Add("x-ms-date", date);
//accept
t = new NameValueHeaderValue("odata", "verbose");
type = new MediaTypeWithQualityHeaderValue("application/json");
type.Parameters.Add(t);
client.DefaultRequestHeaders.Accept.Add(type);
result = await client.PostAsync(joburl,json);
the url:https://wamsamsclus001rest-hs.cloudapp.net/api/Jobs
the json:
{"Name":"khgfiuydencodingjob","InputMediaAssets":[{"__metadata":{"Uri":"https://wamsamsclus001rest-hs.cloudapp.net/api/Assets('nb%3acid%3aUUID%3ad037b321-cd1c-43a9-9607-c4910fa7a85b')"}}],"Tasks":[{"Configuration":"H264 Adaptive Bitrate MP4 Set 720p","MediaProcessorId":"nb:mpid:UUID:1b1da727-93ae-4e46-a8a1-268828765609","TaskBody":"<?xml version=\"1.0\"encoding=\"utf-8\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset>JobOutputAsset(0)</outputAsset></taskBody>"}]}
The bearer token works as I use it for other request.
But I get a bad request 400 with the followin error message:
{"error":{"code":"","message":{"lang":"en-US","value":"Parsing request content failed due to: Make sure to only use property names that are defined by the type"}}}
Can anyone spot the error.
Thank you for the help
Okay I got it to work. Needed a odata=verbose in my json/string content - like this:
var jobInJson = JsonConvert.SerializeObject(job);
json = new StringContent(jobInJson, Encoding.UTF8);//,
json.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata=verbose");
I tried this earlier however I got a error 500 but now it is working.

FQL returns 400 Error on application but works well on browser and API Explorer

The following FQL query works when i paste it on my browser and also works in the API explorer (xxxx is replaced with numbers as well as access token)
https://graph.facebook.com/fql?q=SELECT page_id from place WHERE (distance(latitude, longitude,"xxxxx","xxxxx") < xxxx)&access_token=<MY ACCESS TOKEN>
When i run the same code from my java application i get an HTTP 400 Error. Any idea what's causing this?
This following code implements the connection. getInputStream() throws an exception (Error 400)
connection = (URLConnection) new URL(url).openConnection();
input = connection.getInputStream();
Did you try to URLEncode the "q" parameter value ?
Something like :
String query = SELECT page_id from place WHERE (distance(latitude, longitude,"xxxxx","xxxxx") < xxxx)&access_token=<MY ACCESS TOKEN>;
String urlString = "https://graph.facebook.com/fql?q=" + URLEncoder.encode(query, "UTF-8"));
connection = (URLConnection) new URL(urlString ).openConnection();
input = connection.getInputStream();