I'm still trying to write a function in JavaScript where the user can type in an artist, and it will return a link to that artist's SoundCloud page.
For example,
/artist beyonce --> https://soundcloud.com/beyoncemusic
But the SoundCloud URLS don't all act the same. For example,
/artist dave matthews band --> https://soundcloud.com/dave-matthews-band.
For this reason, I can't simply just output scLink/artistName because they all have different URLs. I'm using Node.js, so I looked through a lot of npm packages, but couldn't figure out how to use any for this purpose. Perhaps Soundclouder will work somehow (though I couldn't figure it out myself). Does anyone know how I could write a command like this?
You are using the SoundCloud API, right?
A simple HTTP request to the right API should return the data you want. For example:
http://api.soundcloud.com/users.json?q=beyonce
[
{
"id": 4293843,
"kind": "user",
"permalink": "beyoncemusic",
"username": "Beyoncé",
"uri": "http://api.soundcloud.com/users/4293843",
"permalink_url": "http://soundcloud.com/beyoncemusic",
"avatar_url": "http://i1.sndcdn.com/avatars-000036935308-a2acxy-large.jpg?435a760",
"country": "United States",
"full_name": "Beyoncé",
"description": "",
"city": "New York",
"discogs_name": null,
"myspace_name": "beyonce",
"website": "http://www.beyonceonline.com",
"website_title": "",
"online": false,
"track_count": 33,
"playlist_count": 2,
"plan": "Pro Plus",
"public_favorites_count": 0,
"followers_count": 478783,
"followings_count": 0,
"subscriptions": [
{
"product": {
"id": "creator-pro-unlimited",
"name": "Pro Unlimited"
}
}
]
},
...
]
...so you could just do results[0].permalink_url.
You can use the request module to make the HTTP request manually, or use soundclouder to handle SoundCloud API's authentication details.
Most of the above does not apply if you want to make the actual requests from a browser. (The question is tagged node.js, but it sounds like you want to do this from a web page.)
If you're doing this from a webpage, use the SoundCloud JS SDK. The data you get back will look like the example above.
I don't think you'd be able to get an exact match reliably. Your best bet would be to search for users with the string you are looking for - example: "beyonce" and then to show the results and let them pick the correct link. You may be able to filter out likely results with follower count (high follower count) or something after you've pulled the initial list from soundcloud.
Search code:
users = SC.get('/users', { q: 'beyonce' });
Then iterate over users and display the permalink url. Hope this helps.
Related
today i have a lil problem for recognize this combination hash is work, im looking when im log into my account in some apps, but i get this hash, and change everytime when i login, even with same password / pin, can someone help me about what is combination is ? im trying to create some desktop apps for personal use.. here the json what body post
{
"rdVerifyInfo": {
"publicKeyP": "3",
"publicKeyAuthen": "pk2",
"softTokenActivated": true,
"dataKey": "ndTWGXgb/D7CeotrgxbtPzQ8jwsJJgz5MaaL5WXtDeXQ0mGkbe1zILYzYoXtcaADQn/rQsBAbl28JAWOgQvU1lq7/r/Vqp/uuCDGcdn2I7AyPq5xeIVdtKuy9/sKq08zs86xRDpNijWYSxIG+iyvatPR+0RFRl7qeysGl6LHpJ6EdwQqOBA0wv6xIAGMmUm4fEgcynHWHuvoPHaY8zhSR40+CLeZm8/WnqwzO9ihtlCy7UU5lLUbcXKJb3MTSea5I1vw2d2oVf+EUqkgoGSCpz4XEd9lagm05SiYnLgMKvv4x7FCKprOuf0pwVBBrun6AS0TvUrMQeKe9affcibyVg==",
"clientCached": 0,
"softToken": "419443",
"publicKeyH": "5",
"data": "swYbclHywLKoY8GsRYw1cz8JrWJKLCSp+qYhLZih0JvOVIpGiFgRHx4MazBslSEI3Mn+dtNp4oSPq93AVrDhf0N4sVfz9lnOyFM1j5TVND/Bl6J0Wpx35QiT9w5rdnfVI+rfBBCCJKIsrvvc8eERRDRBEtMEPl0Sen51AFN+YDEgncqLqs9NMoxsOZU/Sq1g0Aj9vHPogoe2eoGAIJfgCHY/WDh4oZDR6+sxrky4BsV1gI5PEeKpOpgzC4+hXkE5wc7bdIhJfMMn2UAFsRaz3l2MEPZSnyTAfkJtaV2Yem5cTbTNRt4wmSxgVPq8lNIZFhBK9/DN7N83b51X+iekZ17COzLc2ucaBoz5RxhGfoUAtoW+3Yc+TXU4Pwe5Ax33qmbqIfn+5AJyVxrSVIxvnq7HsgpOKjGo61bibXD/kGKds/tqt+3MMoX/yCFlpLEMegstaeIFFH6bd7A3NH/A3jQGbVnWCtN5UCOwQ5ar+Q/KFPPLUCgYiYG66+/cHajUIihQX4Um7qtKhMAgn/R4/rDBgGMrD0wo3EguVUwMEpbPHWC2Mbhyk2gei6xWTe7aelsdlG5ChnZkMLau0eO6e3xthwONXG9B+FRAdz4t7yYK6xsyZ55X0vvvuzIeRW9PNSuOlwCPT5pEdM+0p1Nakf6ncbZ99UeCAlNspsW2vhp9I6tQ2tUk7WgXH/BDUnF/6+BR0HYRH3QhH31I/HYxcGcIxa6cGe1IXH+m9Fm+uRifVfnKMenQaSAkWdSvD6iy3imHjJSm6rpBeQxjuOM1Y3ogWqlk1ZWuIlpufM7roIHtOZs2aY7QDNRFoh+ZS9qw3V9JBNPGhwUBJBvEPC9BHLXp6JKZQyNKn9piX/cYzFeilfsK/MzYJ9lwSRvZ+8Ppd82mJsmc93RPia/SQwy3NjZueEF6nBCIt2OxlQmvVmE=",
"random": "1670082073462_1569060844",
"deviceFingerprint": "1670082071590|49|kD7X+O+YmGNSQK+Pt9TCVThgA835mFptacKw51GwMzL7ksIpJGcXZbVIfC2D0Ntw5IZ57aI=|ujMFdCiBFl43liyc|zvfvmDWtH7A7WA10uwczag==|02",
"action": "LOGIN_PASSWORD_VERIFY"
},
"loginType": "PIN",
"scene": "LOGIN",
"encryUid": "N1G0Z6SMcHx2DBGLgjpPkg==",
"step": "BE",
"cyCode": "62"
}
is anyone familier with this hash combination ? im stuck.
Knowing About Combination Hash
When I click I a link (or am getting redirected by a site), I want to replace the values of assorted tracking parameters in the requested URL with a different, universal value. For this example, let's use my username, so a link that directs to
www.abc.com/?utm_source=originalsource&utm_campaign=originalcampaign&cid=originalcid&gclid=originalgclid
would become www.abc.com/?utm_source=WTTDOTM&utm_campaign=WTTDOTMcampaign&cid=WTTDOTM&gclid=WTTDOTM
It’s important that these parameters get edited before the request is sent off, as the idea is to avoid the UTM/cid/gclid/etc tracking and leave a mark in the traffic data of whoever is looking at those tracking parameters. I know I have to use webRequest, and the logic seems pretty simple, but I don’t know how to find-and-replace in the URL on the fly with js. This answer looks like its the closest to what I’m asking, but I don’t know how it would work with just modifying smaller slices of a URL as I'm pretty inexperienced with javascript and most of my coding knowledge is just slapping stuff together until it works.
To start with a simple sub-problem my question is: how can I use the webRequest API to replace utm_campaign=*** in a URL with utm_campaign=WTTDOTM before the page is requested?
----EDIT:-----
#wOxxOm thank you for your helpful answer! I think I have the general structure down now, but I am still struggling with the formatting of regex rules, which I'm pretty unfamiliar with. The way I understand it, the rule ^(.*?utm_source=)(.+?(?=\\&)|$)(.*) (and its "medium" variant) will capture all values before 'utm_source=' into group 1 and all values (or none in the case of it being the last parameter) after '&' into group 3 and then I should be able to make the regexSubstition group1+WTTDOTM+group3, right? When I currently try to upload the unpacked extension below, I get hit with an error that says "rules.json: Rule with id 1 specifies an incorrect value for the "regexFilter" key." I think I am just formatting it wrong, but I do not know what I need to fix. Can you help? Here are my rules.json and manifest.json files.
rules.json
[
{
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "\\1WTTDOTM\\3"
}
},
"condition": {
"regexFilter": "^(.*?utm_source=)(.+?(?=\\&)|$)(.*)",
"resourceTypes": [
"main_frame"
]
}
},
{
"id": 2,
"priority": 2,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "\\1WTTDOTM\\3"
}
},
"condition": {
"regexFilter": "^(.*?utm_medium=)(.+?(?=\\&)|$)(.*)",
"resourceTypes": [
"main_frame"
]
}
}
]
manifest.json
{
"manifest_version": 2,
"name": "WTTDOTM is a UTM",
"version": "1.3",
"permissions": [
"declarativeNetRequest",
"declarativeNetRequestFeedback",
"<all_urls>"
],
"description": "Replaces all UTM values with 'WTTDOTM'",
"declarative_net_request" : {
"rule_resources" : [{
"id": "1",
"enabled": true,
"path": "rules.json"
},
{
"id": "2",
"enabled": true,
"path": "rules.json"
}],
"icons": {
"128": "icon128.png" }
}
}
It's probably not impossible to do this with regular expressions but it's going to be frustrating. The text that you're trying to capture could contain almost anything, so building a regex that captures what's after each query parameter and only what's after each query parameter is going to be difficult. Instead I would suggest using Chrome's built in URLSearchParams API.
Combined with Javascript's URL object, what you're trying to do would probably look like this:
const replaceTrackerParams = (urlString, replacementString) => {
const url = new URL(urlString);
const params = new URLSearchParams(url.search);
// If campagin parameters exist, replace them
params.has('utm_source') && params.set('utm_source', replacementString)
params.has('utm_campaign') && params.set('utm_campaign', replacementString)
// Return modified URL
return url.hostname + '?' + params.toString()
}
Replace shorthand syntax with more complicated logic as needed.
Another answer suggested using declarativeNetRequest because it is the newer, more efficient API. This is true, but I don't think it supports callback functions yet.
I'm trying to use the Web Service component of a Qualtrics survey to get data from a mailing list based on an answer provided by the person completing. So they would select "Bob Jones" and then the Web Service would look at the mailing list to then populate the email address for Bob Jones.
I'm able to call the mailing list and see results successfully with the API token, however, any time I try to add a query, I get a return of "Unexpected json key provided"
How can I access a specific entry? The format of the returned list follows:
{
"result": {
"elements": [
{
"id": "abcdefghijk",
"firstName": "Bob",
"lastName": "Jones",
"email": "bobjones#stackoverflow.com",
"externalDataReference": "Jones, Bob",
"embeddedData": {
"PrimaryEmail": "bobjones#stackoverflow.com",
"DisplayName": "Jones, Bob"
},
"language": "null",
"unsubscribed": false,
"responseHistory": [],
"emailHistory": []
},
I'm attempting to add the query where it says Parameter to Web Service...:
I greatly apologize if this has been discussed already. I searched through as many questions as I could, and didn't find an answer to this. Hope someone will help!
The API you are trying to use doesn't accept query parameters and you can't use it to get data for a specific contact.
Whether you can do it at all depends on whether your account has XM Directory or Research Core Contacts. If you have Research Core Contacts, the only way to get data for a specific contact is by contact id. If you have XM Directory you can use the search API. See: https://api.qualtrics.com/api-reference/reference/contacts.json/paths/~1directories~1{directoryId}~1contacts~1search/post
I would like to get the live results from an Api endpoint preferably using javascript, nodejs. I am looking for more like a technique or idea how to handle this.
Api response looks as following:
[
{
"id": 6,
"team1": {
"name": "Home Team",
"goals": 2
},
"team2": {
"name": "Away Team",
"goals": 1
},
"starting": "2018-09-14T15:30:00Z"
}
]
Probably one way I can think of doing is making a new request every second and get up to date. So each time a team scores this api changes so I get the latest score goal results.
What is the best way I can handle this without overwhelming the resources of the server or probably not get banned from the API Endpoint if I am doing too many requests.
I am trying to get the duration of a youtube video via search
var request = gapi.client.youtube.search.list({
q: q,
type : "video",
maxResults : 10,
part: 'snippet,contentDetails'
});
as an additional part parameter I added contentDetails in order to get the duration as you can see in their doc.
https://developers.google.com/youtube/v3/getting-started
Now comes the silly part. The response I get is the following:
[
{
"error": {
"code": -32602,
"message": "contentDetails",
"data": [
{
"domain": "youtube.part",
"reason": "unknownPart",
"message": "contentDetails",
"locationType": "parameter",
"location": "part"
}
]
},
"id": "gapiRpc"
}
]
"As such, the part parameter requires you to select the resource components that your application actually uses"
Thats what I did and now they dont know their own parameter anylonger?
So I was wondering how can I retrieve the duration order contentDetails in general?
best
phil
As written in the document, for search->list call, part can only take value "snippet".
Depending on the kind of the response, as a secondary call, you can do one of videos->list, playlists->list, channels->list with the id and part=snippet,contentDetails to get more details of each result item.