Get real-time comments from videos live Facebook-live-api - facebook

I'm setting up an endpoint to receive real-time comments from the live streaming video, I follow the steps in this document smoothly: https://developers.facebook.com/docs/graph-api/server-sent-events/endpoints/live-comments/.
There was one person who commented directly on my live streaming video twice, and I also got those 2 comments, but that person's "id" in 2 comments is different. Can anybody explain me on this, and is there any way to fix it.
var source = new EventSource(
'https://streaming-graph.facebook.com/{live-video-id}/live_comments?access_token={access_token}&comment_rate=one_per_two_seconds&fields=from{name,id},message');
source.onmessage = function(event) {
console.log(event.data);
};
response 1:
{ "from": { name: "Joe Commenter", "id": 126577551217199 },"message":
"I like it!" }
response 2:
{ "from": { name: "Joe Commenter", "id": 23567175551752 },"message":
"Great photo!" }

They're two different accounts, probably a bot building a profile to be used for spam later.

Related

POST request to JIRA REST API to create issue of type Minutes

my $create_issue_json = '{"fields": { "project": { "key": "ABC" }, "summary": "summary for version 1", "description": "Creating an issue via REST API", "issuetype": { "name": "Minutes" }}}';
$tx1 = $jira_ua->post($url2 => json => decode_json($create_issue_json));
my $res1 = $tx1->res->body;
I try to create a jira issue of type Minutes but POST expects some fields which are not available in the issue of type Minutes. The below is the response.
{"errorMessages":["Brands: Brands is required.","Detection: Detection is required."],"errors":{"versions":"Affects Version/s is required.","components":"Component/s is required."}}
I also tried to fetch the schema using createMeta api but don't find any useful info. The below is the response from createmeta.
{"maxResults":50,"startAt":0,"total":3,"isLast":true,"values":[
{
"self":"https://some_url.com/rest/api/2/issuetype/1",
"id":"1",
"description":"A problem which impairs or prevents the functions of the product.",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=25683&avatarType=issuetype",
"name":"Bug",
"subtask":false},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/12",
"id":"12",
"description":"An issue type to document minutes of meetings, telecons and the like",
"iconUrl":"https://some_url.com:8443/secure/viewavatar?size=xsmall&avatarId=28180&avatarType=issuetype",
"name":"Minutes",
"subtask":false
},
{
"self":"https://some_url.com:8443/rest/api/2/issuetype/23",
"id":"23",
"description":"Used to split an existing issue of type \"Bug\"",
"iconUrl":"https://some_url.com:8443/images/icons/cmts_SubBug.gif",
"name":"Sub Bug",
"subtask":true
}
]
}
It looks like there Jira Admin has added these as manadatory fields for all the issuetypes which I came to know after speaking with him. He has now individual configuration for different issue types and am able to create minutes.

Email alert based on monitors going down / coming back up

I am fairly new to this but I need some help with my watcher setup. - I am using the X-Pack Watchers.
I have setup Heartbeat and I currently have 7 monitors.
i.e
monitor-01
monitor-02
etc.
I need help setting up my exact scenarios, I need help with 3 scenarios:
Scenario 1:
If monitor-01 goes offline, I want to send ONLY 1 email to "test#domain.com" with the body of: "Hello there, monitor-01 just went offline! Please check, thanks."
If monitor-02 goes offline, I want the exact same result as above.. I dont want multiple emails alerting me every second / minute if the monitor is down, I only want 1 email.
Scenario 2:
If monitor-01 or any my monitors are offline... Every 3 hours, I want a refresh email sent out (I would like the email body to contain how long the specific monitor is down for, i.e monitor down for 120hours 13 minutes). So, if 3 hours pass, I want to send an email to "test#domain.com" with the body of: "Hello there, this is a reminder email that monitor-01 is still offline! Please check, thanks."
Scenario 3:
If any of the monitors come back online, I want to send out an email to "test#domain.com" with the body of: "Hello there, great news! monitor-02 is back online. The monitor was down for 7hours 12 minutes. Thanks."
Can someone please assist? I looked everywhere and cannot find the correct syntax to create the above scenarios. These would be scenarios I feel could benefit other members of the community.
P.s, I currently have an advanced watch that I found in the forums but does not match my criteria. Here is the code for it:
{
"trigger": {
"schedule": {
"interval": "30s"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"heartbeat-*"
],
"rest_total_hits_as_int": true,
"body": {
"query": {
"bool": {
"must": {
"match": {
"monitor.status": "down"
}
},
"filter": {
"range": {
"#timestamp": {
"from": "now-50s"
}
}
}
}
},
"aggregations": {
"by_monitors": {
"terms": {
"field": "monitor.name"
}
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gt": 0
}
}
},
"actions": {
"email_admin": {
"email": {
"profile": "standard",
"from": "noreply#domain.com",
"to": [
"test#domain.com"
],
"subject": "Monitor is DOWN: {{ctx.payload.aggregations.by_monitors.buckets.0.key}}",
"body": {
"text": "Hello, there is a monitor offline currently. Please check..."
}
}
}
}
}
The above script I put together sends an email every 30 seconds if a monitor is down which is not what I want.
Here is what the email says when everything is put together:
Subject: Monitor is DOWN: [UAT] Test Website
Body: Hello, there is a monitor offline currently. Please check...
Can someone assist with my scenarios? I spent days on this already.. many hours gone in, not much to come out from it!
Thanks.
There are two things you could look into: throttling and acknowledging notifications
throttling: once an action is done (eg sending an email), don't do that action again for 3 hours
acknowledge: : in this case you need to call the API to say: "I did receive the notification that watcher01 has found an error, don't send any notifications about it again."

Instagram API response with users not in caption

I want to know what users are tagged in a photo on Instagram, who don't appear in the caption.
Anyone know if this is possible? That is, does the response contain users that are tagged, but that are not physically in the caption text?
https://www.instagram.com/developer/endpoints/tags/
The property you probably want is called users_in_photo. It is an array which contains an array of user objects who've been tagged in the photo. It also contains the geometric coordinates in the photo that the user has been "tagged" at.
Here is an example response using the /media/MEDIA_ID endpoint:
Endpoint Documentation -> https://www.instagram.com/developer/endpoints/media/#get_media
{
"data": {
"users_in_photo": [{
"user": {
"username": "kevin",
"full_name": "Kevin S",
"id": "3",
"profile_picture": "..."
},
"position": {
"x": 0.315,
"y": 0.9111
}
}],
// rest of object...
}
}
I think what you are looking for are username mentions in captions and comments, API does not return this list in API, you will have to search for #usernames in the caption string.
You will have to make a separate API call to get the comments in post (u can only get latest 120), and do a manual string search in each of the comments.
users_in_photo in API response will have an array of users that are actually tagged on photo, not username mentions

Facebook API endpoint to get campaigns of a certain objective?

I'm trying to fetch all of my ad campaigns from Facebook whose objective is "WEBSITE_CLICKS" (ie, driving visitors to your site). When I make a GET request against the following:
/act_myaccountid/adcampaign_groups?fields=objective,name
or, using the official Python Ads SDK:
fields = [facebookads.objects.AdCampaign.Field.objective, facebookads.objects.AdCampaign.Field.name]
campaigns = my_user_account.get_ad_campaigns(fields=fields)
I get something that looks like:
{
"data": [
{
"objective": "NONE",
"name": "name1",
"id": "1234"
},
{
"objective": "NONE",
"name": "name2",
"id": "567"
},
I'd like to be able to only get campaigns with that particular objective. Is there a way to do this? I read through the Ads documentation but didn't see anything.
It's not documented as far I've seen but the FB Ads Manager UI allows such filtering which also happens to work in external Graph API calls.
Make a call to the API with a filtering parameter like so:
filtering=[
{
"field":"<FIELD>",
"operator":"IN",
"value":[
"<VALUE>"
]
}
]
For example, your request would be:
/act_myaccountid/adcampaign_groups?fields=objective,name&filtering=[{"field":"objective","operator":"IN","value":["WEBSITE_CLICKS"]}]

Getting attachments from Facebook conversations

I currently use the Facebook Graph API to get a inbox conversation. Most of the messages look like this:
{
"id": "1452301718360191_1407164668",
"from": {
"id": "10203840837848742",
"name": "Øyvind Knobloch-Bråthen"
},
"message": "Some message",
"created_time": "2014-08-04T15:04:28+0000"
}
However, some of the messages in the conversation are images, and they are represented like this:
{
"id": "1452301718360191_1407164668",
"from": {
"id": "10203840837848742",
"name": "Øyvind Knobloch-Bråthen"
},
"created_time": "2014-08-04T15:04:28+0000"
}
So basically what is different is that the message is gone. But since there is no mention of the attachment, or url to the image or anything else I can use, I'm not able to display the image in my app.
So my question is: How can I get a hold of the image (or url to the image). Hopefully it will be available in some way when I have the message ID.
With Graph api V2 the egde to retrieve inbox messages is /id/conversations
id is eitheir a user id or a page id
Each conversation message with attachment should return an "attachments" field.
Then for each message with attachment you should query the url https://api.facebook.com/method/messaging.getattachment?mid=message_id&access_tokes=your_access_token
Note that it does not work with graph api v2.1. Unless you curl the query