How to write Spotify API in processing? - api

For my project in college I have decided to make an interactive map where, when the user hovers over a country the title of the top song in that country is displayed. I wanted to get that title from Spotify charts.
I have read every single page of the Spotify API guide and I am still confused as to how should I write the query in processing. I have the authorisation code and the OAuth token, but I'm not sure how should I include it in the actual sketch.
I really need all the help I can get, I am very new to this and I will appreciate every bit of advice.

Use a Spotify API Java Wrapper such as this one to handle API requests to Spotify.
Wrappers are external libraries that simplify API interfacing by providing functions that you can call from your code to make API requests. See this webpage for information about including external libraries in Processing sketches if you haven't done this before.
The most-played track per country isn't likely to change during operation of your program so requesting (it seems you've identified the correct API endpoint for this) the top track for each country just once is sufficient. This process could be done in setup(), for example, since it runs once only.
Then it's a matter of storing the data from these requests in some sort of data structure to allow your program to retrieve the most played track of the country that is being hovered over. A HashMap of country name to top track is appropriate, but there are many viable approaches.

Related

How to add pagination in API

I want to know how to add pagination in APIs for enhanced data retrieval most specifically the youtube API!
I didn't try out anything so far as it's a new concept towards me!
What i personally do usually is one of two things,
(the most preferred way for me) I create more than one API Token. every X requests i dynamically change the API that executes the request., then it avoids throttlings.
When requesting or sending a large amount of requests, you can stop dynamically every X time.

Retrieve Steam game data using API request

I'd like to know how to create an API call to the Steam web API in order to retrieve all the relevant data for a specified game. I found an example call that almost does what I need, except this call requires you to know the Steam app ID as you can see below:
http://store.steampowered.com/api/appdetails/?appids=730
As you can see if you click on the link, all the information I need is returned with the API call. However I'd like to know if it's possible to modify this API call so that it returns the required information using the game name rather than the Steam ID number?
Unfortunately I don't think this is possible (although the lack of official documentation of the API means I may be wrong).
Firstly, from a design perspective it probably wouldn't work - games could have the same name and so name is not a unique enough reference to identify an item (which is a fundamental concept of a correctly designed REST API).
Secondly, all examples (such as this here) I have come across on the web of people self-documenting the API use appID to identify a game/software and have found no cases of being able to use name. The other documented Steam DEV APIs also use AppId

soundcloud API - Application Registration During Early Dev

My team is experimenting with Soundcloud for the first time, and we would like to play with the API before making any strong decisions. So, we do not have an application URL or application name. From my interpretation of the registration process (https://docs.google.com/forms/d/e/1FAIpQLSfNxc82RJuzC0DnISat7n4H-G7IsPQIdaMpe202iiHZEoso9w/viewform), such information is required.
Is there a way for organizations in our position to experiment extensively with the API?
I believe I was able to leave those fields blank and/or put in placeholder fields and I was able to use the API normally.

Soundcloud API returns empty

Thanks in advance for the help.
So while developing an application, I need API data and I retrieve JSON objects. Not a big deal, but with one certain account it doesn't work.
https://api.soundcloud.com/tracks/257255126?client_id=CLIENT_ID_HERE
The ID 257255126 is a track from this profile: https://soundcloud.com/discoverysounds1/.
Every track from this profile returns empty from the API while the same API link works if I insert a track ID from any other profile.
I've already notified the owner of the problem and he hasn't done anything weird or disabled API access if that's even possible.
What could be the problem here?
Thanks,
Jordan
I just tested this with a website I am developing using the API.
If I add one of the tracks to an existing playlist that I have created to test certain functionality, the track does not appear in the playist when retrieved via the /me/playlists endpoint.
When I load the playlist into the soundcloud widget, the track is visible and unrestricted (as in full duration and not a 30 second preview).
I am seeing similar behaviour with tracks that are marked as "soundcloud go" not being visible in the playlist tracks from the /me/playlists endpoint, but available via the widget when the playlist is loaded (albeit only a 30 second preview in their case).
Those items are identifiable as having a "SUB_HIGH_TIER" monetization_model
The track I loaded from your example
There seem to be various issues with the API right now related to the implementation of "soundcloud go"

Can client side mess with my API?

I have a website that revolves around transactions between two users. Each user needs to agree to the same terms. If I want an API so other websites can implement this into their own website, then I want to make sure that the other websites cannot mess with the process by including more fields in between or things that are irrelevant to my application. Is this possible?
If I was to implement such a thing, I would allow other websites to use tokens/URLs/widgets that would link them to my website. So, for example, website X wants to use my service to agree user A and B on the same terms. Their page will have an embedded form/frame which would be generated from my website and user B will also receive an email with link to my website's page (or a page of website X with a form/frame generated from my server).
Consider how different sites use eBay to enable users to pay. You buy everything on the site but when you are paying, either you are taken to ebay page and come back after payment, or the website has a small form/frame that is directly linked to ebay.
But this is my solution, one way of doing it. Hope this helps.
It depends on how your API is implemented. It takes considerably more work, thought, and engineering to build an API that can literally take any kind of data or to build an API that can take additional, named, key/value pairs as fields.
If you have implemented your API in this manner, then it's quite possible that users of this API could use it to extend functionality or build something slightly different by passing in additional data.
However, if your API is built to where specific values must be passed and these fields are required, then it becomes much more difficult for your API to be used in a manner that differs from what you originally intended.
For example, Google has many different API's for different purposes, and each API has a very specific number of required parameters that a developer must use in order to make a successful HTTP request. While the goal of these API's are to allow developers to extend functionality, they do allow access to only very specific pieces of data.
Lastly, you can use authentication to prevent unauthorized access to your API. The specific implementation details depend largely on the platform you're working with as well as how the API will be used. For instance, if users must login to use services provided by your API, then a form of OAuth may suffice. However, if other servers will consume your API, then the authorization will have to take place in the HTTP headers.
For more information on API best practices, see 7 Rules of Thumb When You Build an API, and a slideshow from a Google Engineer titled How to Design a Good API and Why That Matters.