How To Specify the fields to Wordpress API v2 - wordpress

I'm using the WordPress REST API in my project and sending a GET request to:
http://myblog/wp-json/wp/v2/posts
and It's working quite alright but I want to specify the fields though I don't know how. I have looked at the documentation and still don't know how to go about it. For example, using the public API:
https://public-api.wordpress.com/rest/v1.1/sites/www.mysite.com/posts?number=100&fields=title,excerpt,featured_image
returns only the specified fields. How do I this with the v2 API?

Here's how to access the a list of titles and excerpts using REST API v2:
https://www.example.com/wp-json/wp/v2/posts?_fields[]=title&_fields[]=excerpt&per_page=100&offset=100

https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
As it states there, the REST API v2 returns a certain set of default fields, and if you want different ones, then you have to implement this as described in that document.

The easy solution to this issue would be to use the ACF to REST API or an equivalent plugin that can extend the REST API for you. I have used this plugin on many sites successfully.
If this is not possible then you will need to modify the response as has been outlined by other answers. You can read more about that here.

You can use ?_fields[]=title&_fields[]=excerpt

Related

WP REST API not retrieving all categories

I am developing a project that is using the WP REST API. After some tests, I realized that it's not retrieving all the categories based on what I am trying to GET. In precise, there are supposed to be 21 results but only 10 come up. Is there some kind of restriction that I am not seeing? Any settings that I'll have to change.
Here is what I am trying:
https://example.com/wp-json/wp/v2/categories?parent=97
I saw this post here, but some of the answers relied on using the WordPress JSON API, which is a plugin that is no longer available due to security concerns.
TIA
I had to look at the documentation more closely. In terse, The default result shows a count of 10. Specifying the per page would change that. So:
https://example.com/wp-json/wp/v2/categories?parent=97&per_page=X
(Change X to the respective number)

Is there an API call to get a list of saved places in Google Maps?

I have a ton of saved places that appear on my Google Maps - but there is no way to manage, filter or search them. Is there a way to access these locations by API?
I scanned the maps api and can't find any reference. Is there another Google API that makes this available?
There do have a REST API can retrieve the saved places.
http://www.google.com/bookmarks/?output=xml
Visit this link to get more information.
https://www.google.com/bookmarks/
There are also api like:
https://www.google.com/bookmarks/find?q=conf&output=xml&num=10000
https://www.google.com/bookmarks/lookup?
But seems like they have been deprecated and most of document are not available anymore. Use them as you own risk.
Currently the list of saved places in My Maps is not available via an API. There is a feature request tracking this you can use to follow along # https://code.google.com/p/gmaps-api-issues/issues/detail?id=2953.
2022: I created a gist for parsing saved places from a shared list via python. It is really unstable because its a quick&dirty solution but maybe it will help someone: https://gist.github.com/ByteSizedMarius/8c9df821ebb69b07f2d82de01e68387d
Edit: The above answer did not yet take pagination into consideration. Please see my answer here.

Getting a Track from a Spotify ID using the libspotify,dll

I can find tracks using the libspotify.dll just fine.
But if I have a Spotify Id like: 7KEYPk9d9hc1rrHVmztrUS. It does not matter if I set "track:" in front.
Actually I am using a .Net wrapper of the dll but that does not give me any results when I give it the Id.
Well. By the way LibSpotify is obsolete. But back to your problem:
If you have a look at their 'new' Web API there is a way to use a search feature (you do not need authorization for this)
https://api.spotify.com/v1/tracks/7KEYPk9d9hc1rrHVmztrUS
Related to LibSpotify I just found an example
https://developer.spotify.com/docs/libspotify/12.1.51/search_8c-example.html

Google API V3 - Which one to use?

I have few questions about the google map v3 which I am planning to use it my intranet website. Before that
1)
I tried sample application by using the below URLs.Both working fine.
Which one is best ? seems both belongs to V3 ? Can i use it for free ?
http://maps.googleapis.com/maps/api/js?sensor=false
http://maps.google.com/maps/api/js?sensor=false
2)
Am planning to use this v3 URL to locate my stationary stores in my state?
Do I need to buy license for that ? If yes, Do i need to change the URL ?
Go into your api console and grab an API key, then go from there:
https://developers.google.com/maps/documentation/javascript/tutorial#api_key
I tried sample application by using the below URLs.Both working fine.
Which one is best ? seems both belongs to V3 ? Can i use it for free ?
http://maps.googleapis.com/maps/api/js?key={API_KEY}&sensor=false
Go for the first one according to official documentation. But the thing is, what happened to your API key anyway!?
As for whether you can use it for free, read here. (Please show your effort before asking things like these)

Calling an API from a wordpress page

Hello All: I am hoping someone can help me with this. I have never done a call to an API and am really out of my depth. What I am trying to do is a call to an API on a wordpress page. Here is what I have from the API:
http://zipcodedistanceapi.redline13.com/rest//distance.///
I have an API key. I have been trying to learn how to do this but there are thousands of ways and am really at a loss how to do this on a wordpress page. Can anyone help?
Thanks so much, Gerard
You can do it in php (here I use file_get_contents):
$distance = file_get_contents("http://zipcodedistanceapi.redline13.com/rest/<api_key>/distance.<format>/<zip_code1>/<zip_code2>/<units>");
Example taken from their site:
http://zipcodedistanceapi.redline13.com/rest/qVuOZidNAe5osYgYHbyK33EHpJD2nKjOFODE6QsH5y6yxnxfy5ZC9DjynXBLHUAm/distance.json/1000/2000/km
You can also use cURL or anything which can call an external page.
To decode json, have a look on json_decode.
Think about caching the values using your database or user cookies if possible to avoid multiple unnecessary requests.
EDIT: Based on the code provided in your comment (I took a fake API key from demonstration purposes):
$distance = file_get_contents("http://zipcodedistanceapi.redline13.com/rest/qVuOZidNAe5osYgYHbyK33EHpJD2nKjOFODE6QsH5y6yxnxfy5ZC9DjynXBLHUAm/distance.json/48433/485‌​01/miles");
print_r(json_decode($distance));

Resources