YouTube API: Uncaught SyntaxError: missing ) after argument list - api

I'm using the YouTube API and I keep getting
"Uncaught SyntaxError: missing ) after argument list" for the second line of code here:
$(".addVideoUrlBtn").on("click", function(){
player.loadVideoByUrl(mediaContentUrl: videoUrl,
startSeconds:0,
suggestedQuality:"large"):Void
})
The code is practically copied and pasted from YouTube api docs here: https://developers.google.com/youtube/iframe_api_reference so I'm not sure why I'm getting an error.

you're taking the docs too literally. The examples shown are a) not valid js (because they aren't supposed to be) b) showing the TYPES of expected argument
when they say
player.cueVideoById(videoId:String,
startSeconds:Number,
suggestedQuality:String):Void
they mean that the function player.cueVideoById takes arguments videoId, startSeconds, and suggestedQuality which are a String, Number, and String respectively and that its return type is Void (nothing)
$(".addVideoUrlBtn").on("click", function(){
player.loadVideoByUrl(url, 0, "large")
})
is that you want

Related

Can't get 'distance_meters' field from react-native-google-places-autocomplete query

In the documentation for the Google API (https://developers.google.com/maps/documentation/places/web-service/autocomplete), it says that if you use the 'origin' param with a (latitude, longitude) value, it should return the field 'distance_meters'.
When I put the api call into my browser (https://maps.googleapis.com/maps/api/place/autocomplete/xml?input=Ar&types=establishment&origin=40.70823656815506,-73.94331559793082&key=<API_KEY>) I do get the 'distance_meters' field, as you can see at the bottom of the image.
However, when I add the same params into the 'query' prop of the GooglePlacesAutocomplete component in react-native, I only get back a few of the fields shown above, and I do not get the 'distance_meters' field.
Please advise me on how to get the 'distance_meters' field using the GooglePlacesAutocomplete field. My code is below, I am console logging the rowData from renderRow.
When you check the GooglePlacesAutocomplete.d.ts source file of the react-native-google-places-autocomplete library, scroll to see the interface Query and you will notice that the origin parameter is not yet included in the library
// #see https://developers.google.com/places/web-service/autocomplete
interface Query<T = AutocompleteRequestType> {
key: string;
sessiontoken?: string;
offset?: number;
location?: string;
radius?: number;
language?: Language;
components?: string;
rankby?: string;
type?: T;
strictbounds?: boolean;
// deprecated. see https://github.com/FaridSafi/react-native-google-places-autocomplete/pull/384
types?: T;
}
In addition, to see all the Autocomplete predictions results, you can use the renderDescription function and log the data since this function determines the data passed to each renderRow (search result).
renderDescription={(data) => console.log(data)}
Here's a sample code where you will see that the distance_meters is not returned since the origin parameter is not defined in the Query interface.
You can file the issue on the github repository here.

Cypress, how to check property exists

I'm new to cypress and am trying a couple of different methods to get a checkbox property...
checkBox().should('have.prop', 'checked')
checkBox().its('checked').should('exist')
The first line works fine but I was expecting the second to also pass but I get a "expected Undefined to exist" response.
Thanks
Assuming checkBox() function returns cy.get('.checkbox'), I think
checkBox().its('checked').should('exist')
fails because checkBox() does not return an object containing just the attributes. It returns the whole element (I think as an array). so you can't use its('checked') directly on checkbox().
Anyways, to do what you are expecting to do, you can use several methods,
using invoke('attr', 'checked')
checkBox().invoke('attr', 'checked')
.should('exist')
using getAttribute js function and expect chai assertion
checkBox().then($el => {
expect($el[0].getAttribute('checked')).to.exist;
})
using attributes in js and (its, wrap) in cypress.
Note: As mentioned earlier, you can't directly use its on the cy.get(). You need to extract the attributes from the object and use cy.wrap()
checkBox().then($el => {
cy.wrap($el[0].attributes)
.its('checked')
.should('exist')
})
you can use any of those methods, but the one I recommend is your first method.
cheers. Hope it helps.

ERROR TypeError: Cannot read property 'project_name' of undefined - Angular 8

My ts code coding is,
this.api.getPay(this.donationId).subscribe(
data => {
this.paymentData = data;
this.paymentDetails = this.paymentData.donationDetails[0];
}
)
My html code is like
Project : <strong>{{paymentDetails.project_name}}</strong><br/>
Status: <strong>{{paymentDetails?.status}}</strong><br/>
Now project_name and Status details will be displayed. Console gets "ERROR TypeError: Cannot read property 'project_name' of undefined"
If I added "?" like
{{paymentDetails?.project_name}}
No Details displayed. But console not having any Error.
This same coding method works well in Angular 5/6.
Any special method for Angular 8 ???
MY console output in TS file is
{
project_name: "test",
status: "true"
}
Previous question is How to Display Values in Angular 8 Shows ERROR TypeError: Cannot read property 'project_name' of undefined
but solution not working
anyone know how to resolve ?
Everything seems good, check if your component doesn't have
changeDetection: ChangeDetectiongStrategy.OnPush
If so, remove it and put back the '?' in the html markup, and then add it back and do the change detection in the subscribe

Component method response object data binding

I am starting to lose my mind in debugging an application that I inherited from a fellow developer who is absent.
I have narrowed down the problem to the following place in code (php files are checked, Vue instances are initialised, there are no syntax errors).
This is my the component that gets initialised:
var RadniStol = Vue.component('radnistol', {
template: '#template-RadniStol',
data() {
return {
tableData: [],
requestData: {
sort: "ID",
order: "DESC"
}
}
},
methods: {
reloadTable: function (event) {
data = this.requestData;
this.$http.post('php/get/radni_stol.php', data).then(response => {
console.log(response.data.bodyText);
this.tableData = response.data.records;
});
},
.
.
.
The PHP file that gets called with the POST method is working correctly, querying the database and echoing the response in a JSON format.
The thing that is making me pull out my hair is the following: the console.log(response.data) outputs the following into the console:
{"records":[{"DODAN_NA_RADNI_STOL":"1","..."}]}
It is an JSON object that I expected to have but when trying to assign it to the data of the component with:
this.tableData = response.data;
or any other way… response.data.records returns ‘undefined’ in the console. I have tryed with JSON.parse() but no success.
When logging types to console:
response variable is a response object with a status 200 and body and bodyText containing the data from the database.
response.data is a string type containing the string JSON with the data from the database.
When trying to use JSON.parse(response.data) or JSON.parse() on anything in the callback of the POST method I get the following error in the console:
RadniStol.js?version=0.1.1:17 Uncaught (in promise) SyntaxError: Unexpected token in JSON at position 0
at JSON.parse (<anonymous>)
at VueComponent.$http.post.then.response (RadniStol.js?version=0.1.1:17)
at <anonymous>
I am really starting to lose my mind over this issue, please help!
Thank you
If response.data is string, with JSON inside, then to access the records field, you should decode it like this:
JSON.parse(response.data).records
Not sure this has something to do with PHP or Vue.js, it is just plain javascript issue.
If it not decodes, than problem is definitely in response.data. For example
{"records":[{"DODAN_NA_RADNI_STOL":"1","..."}]}
is not a valid JSON, because key "..." needs to have some value.
But it seems to me that response.data is already parsed.
What I suggest you to do, is to write handler of the response as separate function, make response object that mimics actual response object by hand, and then test it separately from request. So you could show us request object and function that works with it.
I had the same error and fixed it.
Result will be response.body not response.data.
Here is my code:
getS: function(page) {
this.$http.get('vue-manager?page=' + page).then((response) => {
var data = JSON.parse(response.body);
this.student = data.data.data;
this.pagination = data.pagination;
});
},

What is Object details in Chrome.* API

I am learning Chrome extension development from the official documentation and learned a bit but I need understanding what it means by object details in API function parameters. For example one of browserAction method getTitle signature is
chrome.browserAction.getTitle(object details, function callback)
//object details integer (optional) tabId
Now I write in background.js
chrome.browserAction.getTitle({}, titleShow);
function titleShow(t){
console.log('tab title:' + t);
}
and it show title of my extension.As you can see here I send blank object {}.
How do I get tabId on very first line and send it with this method?
Does this method return tab Title if we send tab id?
You are asking questions that are easy to answer, just check the documentation and you'll see the details of the chrome.browserAction.getTitle() method (and all the other methods of the Chrome APIs).
Quoting from the documentation:
chrome.browserAction.getTitle(object details, function callback)
Gets the title of the browser action.
Parameters:
object details:
integer (optional) tabId. Specify the tab to get the title from. If no tab is specified, the non-tab-specific title is returned.
function callBack. The callback parameter should be a function that looks like this: function(string result) {...};
string result.
So, to answer your questions:
To get the tab id on the first line you've got to use the chrome.tabs.query() method (see documentation), request the tab with the details you're interested in and use its ID in the callback, something like this:
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.browserAction.getTitle({tabId: tabs[0].id}, function(result) {
console.log("Browser action title:", result);
});
});
Browser actions can have different titles on different tabs. To set a different title for each tab you have to use the chrome.browserAction.setTitle() method. So if you send the tabId in the details object of the chrome.browserAction.getTitle() method, you'll not get the tab title, you'll only get the tab-specific title of the browser action. To get a specific tab title you should use the chrome.tabs.query() method.