Load Facebook adinterests list in a single API call - facebook

Is there a way to load multiple adinterests by IDs in a single API call?
Here's situation:
We have multiple adinterests for ads targeting campaign. For example, we are targeting users that are interested in:
music (ID=111)
arts (ID=222)
museums (ID=333)
We are listing all interests to a user, but in the database we store only IDs.
Currently we can only load single interest per request, e.g.:
https://graph.facebook.com/v2.3/111?access_token=___
https://graph.facebook.com/v2.3/222?access_token=___
https://graph.facebook.com/v2.3/333?access_token=___
or
https://graph.facebook.com/v2.3/?access_token=___&type=adinterest&id=111
This works. However, I would like to load all interests in a single call to speed up page load, for example:
https://graph.facebook.com/v2.3/?type=adinterest&id[0]=111&id[1]=222&id[2]=333&access_token=___
This, unfortunatelly, does not work.
So, is there any way to load ad interests list by list of supplied IDs?

You can use the Batch request framework to make a single HTTP request to multiple endpoints. See
https://developers.facebook.com/docs/marketing-api/batch-requests

Related

REST URLs for schemas and forms

I am designing an application that will expose a REST API.
URLs for the resources themselves will look fairly standard, like below:
GET /orders //Get all orders
GET /orders?somefilter=somecriteria //search for orders
GET /orders/<orderid> //specific order
PUT /orders/<orderid> //update a specific order
POST /orders //create an order
My question is regarding resources related to these. I expect the resources will mainly be accessed through an app, but still would like want to provide basic web entry forms, as well as schemas for various resources. What url should they have?
Possible urls
//Option1
GET /forms/orders //new order
GET /forms/orders/<orderid> //edit existing order
GET /schemas/orders
//Option2
GET /orders/form //new order
GET /orders/<orderid>/form //edit existing order
GET /orders/schema
//Option3
GET /orderform //new order
GET /orderform/<orderid> //edit existing order
GET /orderschema
Option 2 doesn't seem right to me, I don't think that the form resource should share the same location on a URL as the order ID. Option 1 looks the best, but would increase the organisational complexity of the app as I couldn't keep the schemas with the rest of the code dealing with a particular resource (but that is a problem that can be solved).
Is there any accepted best practice for these? It does not have to be one of the three options above, any and all pointers would be appreciated.

How can I query multiple object insights in one Facebook API Call?

I saw this question (Query multiple insights metrics in one API call) but their answers are from 2012 and no longer work.
I want to get post_video_avg_time_watched and post_video_views in a single api call to Facebook.
How is this possible?
I don't want to use Facebook's batch request, because it counts against my rate limits twice instead of once.
Yes, and easily! Just add the second value after a comma and the first value like so: /insights/post_video_views,post_video_avg_time_watched/lifetime

Ember CLI - Custom routing for very basic dropdown

New to ember and ember cli, and not having any JS based framework experience apart from jQuery (which is not a framework)
I find my self stuck at the very beginning compared to work done in Angular,
I have a static list of groups which are on REST api `http://localhost:8000/api/groups' and it is only 8 items there, I needed to show them as dropdown for a search criteria. Nothing fancy
I started with creating a route and model with the name of groups but app stopped working and I had to create a model for group which is identical to groups model, only having 2 items for dropdown
Now i have a url in my ember app http://localhost:4200/groups which I dont need and i dont want it to be there,
But I ignored it and had to create a dropdown of the cities, api is
http://localhost:8000/api/cities <-- All cities list, needed for admin
http://localhost:8000/api/cities/active <-- For clients to show active cities so they can add their records
http://localhost:8000/api/cities/filled <-- For users, to show them where clients are available
So in ember, I created a route and model for cities, and same model is copied as city just to show the list of cities in dropdown, I needed to show cities which are filled, I had created ember g route city/filled and it created folders, but its model is also same like other two models.
Ajax call is not being sent to city/filled url and now I ended up having
http://localhost:4200/cities // useless for me
http://localhost:4200/cities/filled //useless for me
and in filled i see that ajax call is made but to the http://localhost:8000/api/cities two times, loading same data. I tried adding a dropdown on my application and opened http://localhost:4200/cities/filled in browswer, and woosh, it send ajax call to the same url 3 times, one for application.hbs and one for cities.hbs and one for city/filled. Why load the same data 3 times if it is already fetched from same url within single request?
in angular I just call a custom url and I can get the data, but for ember its really hard to get grip on these small things and there is no help around
active and filled are filters for your cities resource and these are not standalone resources, so you should try to use them as query parameters. like
http://localhost:8000/api/cities?type=filled
http://localhost:8000/api/cities?type=active
Facebook uses this style for query params. You can also use query params for getting paginated data of a resource, like for 1st page and 25 records per page, the request will look like:
http://localhost:8000/api/cities?page=1&records=25

How to perform Action in Rest API

I try to create a pdf ON Server but what will be the Rest URL? I.e. For a List of all Clubs in one Region GET /clubListForRegion/3
Thanks!
The design of the resource depends on your application domain. If you offer some service for browsing different entertainment branches and you can drill down into certain regions I would propose
GET /regions/north-east/entertainment/clubs
and the representation of this collection of club resources would be a PDF.
If you are offering some service specialised on browsing clubs, you could shorten the hierarchy or use a query parameter:
GET /clubs/techno?region=north-east
If the on the fly creation of the PDF takes a noticeable amount of time, I would propose a POST on the resource instead. The response could contain a link to the final PDF and possibly a link to query the status of the PDF creation process.

Order by playbacks when fetching tracks from SoundCloud

I am fetching a list of tracks from soundcloud's API using the following query to retrieve the 5 most popular tracks:
https://api.soundcloud.com/tracks?client_id=XXX&order=hotness&limit=5
But recently SoundCloud removed the hotness order. In the blog post they say tracks can instead be sorted by playback_count. But can this be done in the query or do they suggest I pull down the whole SoundCloud library and order them in the client? The following doesn't seem to work:
https://api.soundcloud.com/tracks?client_id=XXX&order=playback_count&limit=5
So how would one retrieve the top tracks on SoundCloud?
The solution was to use the undocumented calls for the explorer feature that SoundCloud itself uses (I used the dev tools in Chrome to check the AJAX calls).
https://api.soundcloud.com/explore/sounds/category?limit=L&client_id=XXX
This appears to use some sort of sorting on the popularity of the songs. The songs can then be filtered on only music by checking the "grouping" attribute. I then have to resolve the list of IDs to actual songs which can be done with the (documented, official) API call:
https://api.soundcloud.com/tracks?ids=1,2,3&client_id=XXX
This seems to work perfectly and I also get the added benefit of an even distribution among genres. But of course, this can stop working at any moment since the API calls are undocumented and perhaps not meant for public use.
Just wanted to provide an update. It seems soundcloud has moved to v2 of the explore API call.
Use this to get a list of categories:
https://api.soundcloud.com/explore/v2
And this to get tracks from a category:
https://api-v2.soundcloud.com/explore/metal?limit=10&offset=0
So far it seems to without a key, although I have no idea how long that will last.
EDIT: So the 2nd url doesn't seem to allow cross-origin, but so far this does work, though it only returns the trackID not the full information
https://api.soundcloud.com/explore/v2/metal?limit=50&consumer_key=XXX
check here, soundcloud removed order by hotness.
Has order by hotness been removed from Soundclouds API
so, for now, only order by date is possible.