How do I retrieve thumbnail from facebook ad api? - facebook

With facebook ad api, I can send a query to retrieve ad image information.
The following is the examples from facebook doc. https://developers.facebook.com/docs/reference/ads-api/adimage/v2.2
curl -G \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/act_<ACCOUNT_ID>/adimages"
curl -G \
-d "hashes=[%220d500843a1d4699a0b41e99f4137a5c3%22,%22012feg987e98g789f789e87976210983%22]" \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/act_<AD_ACCOUNT_ID>"
Both calls work fine. But the problem is: they return just the array of image id and image hash, nothing else. Again, example from facebook doc. My test shows response with the same format.
{
"data": {
{
"hash": "0d500843a1d4699a0b41e99f4137a5c3",
"id": "16522000:0d500843a1d4699a0b41e99f4137a5c3"
},
{
"hash": "012feg987e98g789f789e87976210983",
"id": "16522001:012feg987e98g789f789e87976210983"
}
},
"paging": {
"cursors": {
"before": "NDIyNDAzMzc0NDY4NjQxOjE2...",
"after": "NDIyNDAzMzc0NDY4NjQxOmU5Njg..."
}
}
}
Ad Image objects are supposed to have 'url', 'width', 'height', properties. But I cannot retrieve anything more than id and hash, whatever I try.
Any way to get thumbnail url or other image properties using image hash or ad account id?
What I want to achieve ultimately is make a migration from manual management to automatic api based management, and get the url/properties of images already uploaded to facebook (to be saved in db and reused when necessary).

Like almost for all the Ad Objects, if you call an Ad Image endpoint without specifying any additional fields you only get and id and, sometimes, a few more parameters.
If you look carefully in the section "Create" of that page you'll find a list of fields; Add the needed one as a field param in your curl request.
Ex.
curl -G \
-d "access_token=<ACCESS_TOKEN>" \
-d "fields=id,url,whatever" \
"https://graph.facebook.com/act_<ACCOUNT_ID>/adimages"

Related

How to use postman to send a request to timekit api

I don't know much about how to use an API, and I am just trying to get a basic understanding so I can use the Timekit.io API in a JS app I am going to build, so to start I though I should try and use postman to learn how to send a request. In the Timekit documentation for finding a time from a resource ie: a persons calendar they say to use this curl command.
curl --request POST \
--url https://api.timekit.io/v2/findtime \
--header 'Content-Type: application/json' \
--user :live_api_key_7nzvc7wsBQQISLeFSVhROys9V1bUJ1z7 \
--data '{
"resource_ids": ["78a4d873-2a68-41c6-bdd4-c0ca5b35efd3"],
"filters": { "or": [
{"specific_day_and_time":{"day":"Monday","start":9,"end":13}},
{"specific_day_and_time":{"day":"Wednesday","start":10,"end": 16}}
]},
"future": "2 days",
"length": "30 minutes"
}'
I am trying to figure out what I put into postman itself so I get the correct Json values. So far I have selected a POST request with the url https://api.timekit.io/v2/findtime and a header with the key Content-Type and value application/json I have no idea where to put the user,data,rsource_ids,filters,future & length Here is a screenshot of my post man setup.
--user sets the authentication. If an authentication type is not specified, then it will default to Basic Authentication. In Postman, click the "Authentication" tab and from the "Type" dropdown, select "Basic Auth". You can then input the username and password into the appropriate fields. With the --user flag, the value should be <username>:<password>. So your case, there is no username specified, so I guess you don't need to input it, just use the api key for the password.
--data is the JSON request body. You can input this entire value (within the single quotes ') into the "Body" tab. Select the "Body" tab, and within the tab, select the "raw" radio button, and from the dropdown to the right, select "JSON (application/json)". Now just put the entire JSON into the text area.
{
"resource_ids": ["78a4d873-2a68-41c6-bdd4-c0ca5b35efd3"],
"filters": {
"or": [
{ "specific_day_and_time":{ "day":"Monday", "start":9, "end":13 } },
{ "specific_day_and_time":{ "day":"Wednesday", "start":10, "end": 16 } }
]
},
"future": "2 days",
"length": "30 minutes"
}
You could just drop the curl request straight into Postman via the Import feature, this would populate the whole request in the application for you.
In the top left of the application UI, select the Import button and then select the 'raw' text option (it’s the last one) - paste the curl request text into the text box. Once imported, that should do the rest for you, if it’s a valid format.

Can I estimate the audience size given the city and the language?

I need to mimic the behavior of the targeting selection screen, just make it simpler, limiting the choice to few languages and a few hundred cities, see the picture of the original screen below. I tried calling
curl -G \
-d 'targeting_spec="{"geo_locations":{"countries":["BE"],"zips":[{"key":"BE:1000"}],"locales":[{"key":"1003"}]}}' \
-d 'access_token=TOKEN' \
https://graph.facebook.com/v2.3/act_AD_ACCOUNT_ID/reachestimate
but I get the message
{
"error": {
"message": "The entity backed by id ENTITY_ID cannot be seen by the viewer with (ViewerID 0, AccountID 0): DENY_RULE:InlinePrivacyPolicy:AlwaysDenyRule:4 (EntID: ENTITY_ID)",
"type": "OAuthException",
"code": 1
}
}
Should I ask for more permissions from Facebook? And how? I am just trying to build a simple website app.
You need to have ads management scope added to your access token and as I take it you are in development mode you need to ensure that the ad account that you are sending requests for is on your account list
https://developers.facebook.com/docs/marketing-api/access#standard_accounts
Your curl command should be as follows:
- You don't need countries and zips as part of geolocations as they overlap
- locales is not part of geo_locations and is not an array of key/value pairs - it is an array of ints.
curl -G \
-d 'targeting_spec={"geo_locations":{"zips":[{"key":"BE:1000"}]},"locales":[1003]}' \
-d 'access_token=[access_token]' \
https://graph.facebook.com/v2.3/[account_id]/reachestimate

Facebook Ads - How can I create a Website Custom Audience based on custom data

I changed the 'Custom Audiences pixel code' to send 'custom data' as explained on https://developers.facebook.com/docs/ads-for-websites/website-custom-audiences/planning
But in Power Editor I can only create Audiences based on the url of the page on my site.
How can I use the custom data to create an Audience ?
You will have the option to segment audiences by events after the custom tag will be fired on your webpage (after one day or so). Then, just go to Create Audience -> Custom Audience -> Website Traffic -> Custom Combination -> Choose Event and voila, you have it.
This is the best hint I could find for your question so far: https://developers.facebook.com/docs/reference/ads-api/custom-audience-website-faq#fbpixel
What they suggest is to create an audience and add a rule, like:
{
'or': [
{ 'url': { 'i_contains': 'signup' } },
{ 'event': { 'i_contains': 'SignUp' } }
]
}
Hence, the question is how create an audience on the fly and include your rule, which they suggest as follows:
curl \
-F "name='my_audience'" \
-F "subtype=WEBSITE" \
-F "retention_days=15" \
-F 'rule={"url":{"i_contains":""}}' \
-F "access_token=_____" \
"https://graph.facebook.com/act_<ad account id>/customaudiences"
So, the final code would be:
curl \
-F "name='my_audience'" \
-F "subtype=WEBSITE" \
-F "retention_days=15" \
-F 'rule={
'or': [
{ 'url': { 'i_contains': 'signup' } },
{ 'event': { 'i_contains': 'SignUp' } }
]
}' \
-F "access_token=_____" \
"https://graph.facebook.com/act_<ad account id>/customaudiences"
Hope this helps!
I found my answer on https://developers.facebook.com/docs/reference/ads-api/custom-audience-website-faq
Q: Are Rules solely based on URLs? Can we apply more complex rules for
sophisticated clients?
A: Via PowerEditor or Ads Manager, rules can
only be configured based on URL, but there is a new JS feature that
will enable PMDs and clients to create any custom audience dynamically
via variables they decide to pass to Facebook.

Send a push to people who don't subscribe to a channel using Parse?

I'm able to send push notifications to mobile clients that subscribe to channels (let's say channel_1 and channel_2 using Parse REST API by POSTing a JSON to https://api.parse.com/1/push:
{
"channels": ["channel_1", "channel2"],
"data": { "alert": "Test" }
}
However, I'd like to send the notifications to people who subscribe to channel_1 and channel_2 but also don't subscribe to another specific channel (channel_3).
Is there a way to do that with Parse REST API? I know I can do that via Parse's admin panel.
I think advanced targeting is a better fit for what you're trying to achieve
https://parse.com/docs/push_guide#sending-channels/REST
It is easier to understand the concept looking at the Javascript documentation and then replicate for REST.
I posted my question on Parse forum, and someone from Parse responded:
In this case, you'll want to use Advanced Targeting. Basically, construct a query over the Installation class that targets objects subscribed to both channels, and don't have the third in the "channels" key.
curl -X POST \
-H "X-Parse-Application-Id: YOUR_APP_ID" \
-H "X-Parse-REST-API-Key: YOUR_REST_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"where": {
"channels": {"$all": ["channel_1", "channel_2"], "$nin": ["channel_3"]}
},
"data": {
"alert": "Hello world!"
}
}' \
https://api.parse.com/1/push

sinatra + mongoid

I'm creating an app that use sinatra + mongoid. I have two models, contact has many phones. To test my sinatra controller I post my data with this command `
curl -X POST -d "contact[name]=nome&contact[email]=email#dominio.com&contact[phone][0][number]=88888888&contact[phone][0][type]=1&contact[phone][2][number]=77777777&contact[phone][3][type]=1"
but when I did one query in mongodb I see that not save as expected. I need that phone class will be save with array, but now phone is a hash where the key is "0", "1", N like my post data. How do I to resolve this problem? I want data to be saved so:
{
"_id":"4f889875b336e722a0000003",
"email":"diego.dias2#dominio.com.br",
"github":"diegodfsd",
"name":"diego2",
"phone":{
"0":{
"number":"89311768",
"type":"cellphone"
},
"1":{
"number":"55555555",
"type":"home"
}
},
"twitter":"diegodfsd"
}
gist
You need use phones_attributes params instead of phone
curl -X POST -d "contact[name]=nome&contact[email]=email#dominio.com&contact[phones_attributes][0][number]=88888888&contact[phones_attributes][0][type]=1&contact[phones_attributes][2][number]=77777777&contact[phones_attributes][3][type]=1"