Get ads and their image in the same query - facebook

I'm using the graph API and trying to get a list of ads with their insights and post images.
I don't want to do multiple queries for this as I quickly hit the "(#17) User request limit reached" issue even when I use batch queries.
My current query looks like this:
/ACCOUNT_ID_HERE/ads?fields=insights{cpc,reach,spend,clicks,ctr},status,creative
Now in order to get the post image, I need to take the creative ID that is returned and use it in another query to pull the post like this:
/CREATIVE_ID/?fields=object_story_id
Then use the returned story id to pull the picture like:
/OBJECT_STORY_ID/?fields=picture
Is there any way I can combine these queries to do less requests?
Something like:
/ACCOUNT_ID_HERE/ads?fields=insights{cpc,reach,spend,clicks,ctr},status,creative{object_story_id{picture}}'
Any help is appreciated. Thanks.

Facebook's Batch API may work for you. It allows for multiple Graph API calls to be made from a single HTTP request and supports dependencies between those requests. Read over the documentation for details and here's a example curl call of how it might work (I've not executed this call so please review against the API documentation and test).
curl \
-F 'access_token=...' \
-F 'batch=[
{
"method":"GET",
"name":"ads",
"relative_url":"/ACCOUNT_ID_HERE/ads?fields=insights{cpc,reach,spend,clicks,ctr},status,creative",
},
{
"method":"GET",
"name":"creative",
"relative_url":"/{result=ads:$.data.*.creative}/?fields=object_story_id"
},
{
"method":"GET",
"relative_url":"/{result=creative:$.data.*.object_story_id}/?fields=picture"
}
]' \
https://graph.facebook.com

Related

How to get more than 350 favorites with SoundCloud API?

I have about 600 likes on my soundcloud (my profile: https://soundcloud.com/bogem/likes) and I try to get full list of my likes.
But I can't get more than 300 favorites:
$ curl 'https://api.soundcloud.com/users/75306957/favorites?client_id=HIDDEN&limit=150&offset=300'
{"errors":[{"error_message":"403 - Forbidden"}]}
Even authorised:
$ curl 'https://api.soundcloud.com/me/favorites?client_id=HIDDEN&limit=150&oauth_token=HIDDEN&offset=300'
{"errors":[{"error_message":"403 - Forbidden"}]}
What do I do wrong or is there any limits?
You'll need to use the linked_partitioning pagination method which will return you a collection object that contains your likes, and a next_href that gives you the URL to paginate to.
There's a blog post about dropping support for offset-based pagination.

Get Reactions using the Github api

Github issues may contain "reactions" for quite a while (as described here: https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments)
I would like to receive that information using the Github api, but there doesn't seem to be anything like that when getting an issue e.g.
api.github.com/repos/twbs/bootstrap/issues/19575
that information does not seem to be inside that response. Also, I did not find another API call that could retrieve that information. How to get those "reactions"?
This is now possible, being the preview state (meaning, you have to pass a custom Accept header in the request). Check out the GitHub API documentation page
Example
$ curl -H 'Accept: application/vnd.github.squirrel-girl-preview' https://api.github.com/repos/twbs/bootstrap/issues/19575/reactions
[
{
"id": 257024,
"user_id": 947110,
"content": "+1"
},
...
{
"id": 888868,
"user_id": 1889800,
"content": "+1"
}
]
The endpoint looks like this:
GET /repos/:owner/:repo/issues/:number/reactions
You can even pass a content parameter (querystring) indicating what kind of reaction you want to retrieve.

Should include_headers be placed that way?

Hitting the Facebook graph api with a batched request:
curl -F 'access_token=mytoken' -F 'batch=[{ "method":"GET","relative_url":"me?fields=name,first_name,last_name,picture.width(100).height(100),email", "include_headers":"false"},
{ "method":"GET","relative_url":"me?fields=picture.type(large)", "include_headers":"false"}]' https://graph.facebook.com/v2.2
The result still contain the headers.
I don't expect them in the result.
Is the "include_headers":"false" syntax wrong or misplaced?
Thanks a lot.
I was able to exclude the headers in batch requests a few different ways. I'm doing it from the PHP SDK but it's all the same under the covers.
By passing it as a POST parameter on the top-level request, i.e. add -F "include_headers=false" to your curl command
By passing it as a GET parameter on the inner request(s), not as a separate field, i.e. append "&include_headers=false" to relative_url
Hope that helps!
If you're using the python facebook-sdk this does the trick:
rezs = self.graph.request("?include_headers=false",
post_args={"batch": batched_requests})
where my self.graph is:
self.graph = facebook.GraphAPI(access_token=access_token,
version="2.5")
and the batched_requests is a string containing the IDs and fields that I want.

Marketo "Import Lead" fails with error 610 Requested resource not found

I'm trying to batch update a bunch of existing records through Marketo's REST API. According to the documentation, the Import Lead function seems to be ideal for this.
In short, I'm getting the error "610 Resource Not Found" upon using the curl sample from the documentation. Here are some steps I've taken.
Fetching the auth_token is not a problem:
$ curl "https://<identity_path>/identity/oauth/token?
grant_type=client_credentials&client_id=<my_client_id>
&client_secret=<my_client_secret>"
Proving the token is valid, fetching a single lead isn't a problem as well:
# Fetch the record - outputs just fine
$ curl "https://<rest_path>/rest/v1/lead/1.json?access_token=<access_token>"
# output:
{
"requestId": "ab9d#12345abc45",
"result": [
{
"id": 1,
"updatedAt": "2014-09-18T13:00:00+0000",
"lastName": "Potter",
"email": "harry#hogwartz.co.uk",
"createdAt": "2014-09-18T12:00:00+0000",
"firstName": "Harry"
}
],
"success": true
}
Now here's the pain, when I try to upload a CSV file using the Import Lead function. Like so:
# "Import Lead" function
$ curl -i -F format=csv -F file=#test.csv -F access_token=<access_token>
"https://<rest_path>/rest/bulk/v1/leads.json"
# results in the following error
{
"requestId": "f2b6#14888a7385a",
"success": false,
"errors": [
{
"code": "610",
"message": "Requested resource not found"
}
]
}
The error codes documentation only states Requested resource not found, nothing else. So my question is: what is causing the 610 error code - and how can I fix it?
Further steps I've tried, with no success:
Placing the access_token as url parameter (e.g. appending '?access_token=xxx' to the url), with no effect.
Stripping down the CSV (yes, it's comma seperated) to a bare minimum (e.g. only fields 'id' and 'lastName')
Looked at the question Marketo API and Python, Post request failing
Verified that the CSV doesn't have some funky line endings
I have no idea if there are specific requirements for the CSV file, like column orders, though...
Any tips or suggestions?
Error code 610 can represent something akin to a '404' for urls under the REST endpoint, i.e. your rest_path. I'm guessing this is why you are getting that '404': Marketo's docs show REST paths as starting with '/rest', yet their rest endpoint ends with /rest, so if you follow their directions you get an url like, xxxx.mktorest.com/rest/rest/v1/lead/..., i.e. with '/rest' twice. This is not correct. Your url must have only one 'rest/'.
I went through the same trouble, just want to share some points that help resolve my problem.
Bulk API endpoints are not prefixed with ‘/rest’ like other endpoints.
Bulk Import uses the same permissions model as the Marketo REST API and does not require any additional special permissions in order to use, though specific permissions are required for each set of endpoints.
As #Ethan Herdrick suggested, the endpoints in the documentation are sometimes prefixed with an extra /rest, make sure to remove that.
If you're a beginner and need step-by-step instructions to set up permissions for Marketo REST API: Quick Start Guide for Marketo REST API

Difference between XPOST and XPUT

I'm just starting to use ElasticSearch. And I tried to know how to insert documents. I only found examples using the PUT method : $ curl -XPUT 'http://localhost:9200/...'
But it also seems to work using POST. Is there any difference between these two methods?
Thank you.
Generally when using a REST API:
- POST is used to create a resource, where the server will pick an ID.
- PUT is used to update OR PLACE a resource at a known ID.
Doc creation examples in the ES documentation show the caller picking an ID.
Like so:
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}'
Since the caller is picking the ID a PUT seems appropriate here.
BUT
using POST Elasticsearch can also generate an ID for you.
$ curl -XPOST 'http://localhost:9200/twitter/tweet/' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}'
Somehow they have the same functionality with small different
PUT verb (“store this document at this URL”)
POST verb (“store this document under this URL”)
in the put you must indicate the exact URL but in the post you can set document by just type
for example:
PUT /website/blog/123 says put this document at exact this URL but POST /website/blog will insert the document in blog and auto increment the id of the last document.