facebook api Campaign time_range - facebook-graph-api

Get data for a specified date.
https://graph.facebook.com/v5.0/campaigns_id?fields=id,name,delivery_status,effective_status,status,spent,daily_budget,frequency,result,insights.time_range({'since':'2020-02-20','until':'2020-02-20'}){impressions,inline_link_clicks,cost_per_inline_link_click,cpm,inline_link_click_ctr}&access_token=XXXXX&time_range({'since':'2020-02-20','until':'2020-02-20'})
I get data for all the time.
How can I get data for a specified date ?

Time ranges can only be applied to "insights" edge here
You can achieve this with this call:
https://graph.facebook.com/v5.0/{your-campaign-id}?fields=id,name,effective_status,status,daily_budget,insights.time_range({'since':'2020-02-20','until':'2020-02-20'}){impressions,inline_link_clicks,cost_per_inline_link_click,cpm,inline_link_click_ctr}&access_token=XXXXX
You only need your first "time_range" in your query

Related

Dynamic query (Current date) via web services in Power Bi

In my project we are consuming the company's data via Web Service REST. Today we don't do the query dynamically by passing the start date and end date parameters via string.
enter image description here
My goal is for the end date to update dynamically. I've already created a query that takes the current date but I can't put it in the parameter without generating an error in the query.
enter image description here
This is the error message I get when I put the column value in the parameter:
enter image description here
I'm pretty sure I'm getting the syntax wrong. Anyone who can help me, I really appreciate it. I would like to point out that the date format for the API call to work is DD/MM/YYYY.
Can you try using
PutYourOtherTableNameHere[Hoje_Coluna]{0}
instead of
[Hoje_Coluna]
?
To see if that will work, put this in right before your query, then click on the step and see what it returns.
x = PutYourOtherTableNameHere[Hoje_Coluna]{0},

Groupby existing attribute present in json string line in apache beam java

I am reading json files from GCS and I have to load data into different BigQuery tables. These file may have multiple records for same customer with different timestamp. I have to pick latest among them for each customer. I am planning to achieve as below
Read files
Group by customer id
Apply DoFn to compare timestamp of records in each group and have only latest one from them
Flat it, convert to table row insert into BQ.
But I am unable to proceed with step 1. I see GroupByKey.create() but unable to make it use customer id as key.
I am implementing using JAVA. Any suggestions would be of great help. Thank you.
Before you GroupByKey you need to have your dataset in key-value pairs. It would be good if you had shown some of your code, but without knowing much, you'd do the following:
PCollection<JsonObject> objects = p.apply(FileIO.read(....)).apply(FormatData...)
// Once we have the data in JsonObjects, we key by customer ID:
PCollection<KV<String, Iterable<JsonObject>>> groupedData =
objects.apply(MapElements.via(elm -> KV.of(elm.getString("customerId"), elm)))
.apply(GroupByKey.create())
Once that's done, you can check timestamps and discard all bot the most recent as you were thinking.
Note that you will need to set coders, etc - if you get stuck with that we can iterate.
As a hint / tip, you can consider this example of a Json Coder.

Combine or Simplify Web Service Queries in Power BI

I was wondering if there was a flexible way to setup multiple web services (API) queries in Power BI. The web service I am using is only capable of getting me one day of data for one location per query and I need daily data for 10 locations. Which means on a standard 31 day month I would need to setup 310 queries. The data I am interested in are the Final LMPs and the website I am pulling from is https://webservices.iso-ne.com/docs/v1.1/. An example of a working query in PowerBI that is grabbing Final LMP data for just 02/01/2020 for location 4152 is:
https://webservices.iso-ne.com/api/v1.1/hourlylmp/rt/final/day/20200201/location/4152.xml
For such case I would setup the following items:
A data source (e.g. manually via 'Enter Data') with 10 individual locations
A data source with the required date range (e.g. something like that)
A data source that combines the the first two (cross join e.g. an example)
Add a column (to source 3) that calls a 'custom function' that for each combined record (in step 3) makes an API request to retrieve the data. The function should take two parameters (location and the day) as the input
Thanks,
Mau
You'll need to create 10 queries, for each of the locations, you can then use a variable to drive the date of extraction.
In the advanced editor after the 'let' add
var_date = Date.ToText(Date.From(DateTime.FixedLocalNow()), "yyyyMMdd")
Which today will return 20200221. When the query runs it will evaluate it and run it for the right day.
https://webservices.iso-ne.com/api/v1.1/hourlylmp/rt/final/day/20200201/location/4152.xml
Change to in your source to something like:
"https://webservices.iso-ne.com/api/v1.1/hourlylmp/rt/final/day/" & var_date & "/location/4152.xml"
So it should be like this:
If you need to offset the date try DateTime.FixedLocalNow() -1 to get the previous day.

Facebook graph api get posts after a certain post id

I am using facebook graph api where I periodically call: https://graph.facebook.com/cnn/posts?access_token=accesstoken
I don't want to get repeat posts the second time I make the call so I would like to filter the call to get anything after either a certain post Id or after a created_time. Is this possible?
I have tried using date_range= but it did not work plus it only allowed me to search by date but not time.
Use timebased paging: https://developers.facebook.com/docs/graph-api/using-graph-api/#paging
The correct parameter would be since and until. Just store the timestamp of the last post and use it in your next call.

get first comment of a Facebook user

I am trying to integrate Facebook API to my web app. I want to check approximately when the user joined Facebook by querying earliest comment like following:
SELECT text, time FROM comment WHERE fromid= me() ORDER BY time ASC LIMIT 1
However, I got error saying:
"message": "Your statement is not indexable. The WHERE clause must contain an indexable column.
How can I fix this issue?
Thank you.
The comment table is for fb:comments, so you need to use the proper table first. This would be the status table. http://developers.facebook.com/docs/reference/fql/status.
SELECT status_id, message, time FROM status WHERE uid=me() ORDER BY time ASC LIMIT 1
But
What if the first post is from another user?
Then we should use the stream table. The first item in the news feed, should theoretically be after the date of joining (why show items before?) This is assuming the API holds all the data for the news feed.
So this will involve playing with streams, filter_keys and created_time
http://developers.facebook.com/docs/reference/fql/stream_filter
http://developers.facebook.com/docs/reference/fql/stream
A FQL query with a WHERE clause must include an indexable column, as shown in the docs for the table (they're now marked with a star, & shown in the Supported Base Where Clauses section).
fromid is not an indexable column so your WHERE clause can't be just a condition on this column.
I don't think it's possible to discover when a user joined Facebook via the Graph API or FQL; there's no property of the FQL User table that gives this, & the Graph API User schema is pretty close to the User table.