Display current number of Facebook group members using JavaScript - javascript

Is there a way to display the current number of members of my Facebook group on a SquareSpace code block (which only accepts HTML and JavaScript)?

Totally.
You can use Facebook Graph to accomplish what you want. Using an ordinary HTTPS request, I got this JSON-formatted results :
{
"id": "165227436975532",
"about": "Salon de Th\u00e9 style traditionnelle ..!!",
"can_post": false,
"category": "Restaurant/Cafe",
"category_list": [
{
"id": "203462172997785",
"name": "Tea Room"
}
],
"checkins": 66,
"cover": {
"cover_id": "476669145831358",
"offset_x": 0,
"offset_y": 54,
"source": "https://scontent.xx.fbcdn.net/hphotos-xpt1/v/t1.0-9/11536065_476669145831358_6075091507244297763_n.jpg?oh=7c6940ee3f2566884609fc59da224b67&oe=563A1B1D",
"id": "476669145831358"
},
"has_added_app": false,
"is_community_page": false,
"is_published": true,
"likes": 1246,
"link": "https://www.facebook.com/arabiccafe",
"location": {
"city": "Sousse",
"country": "Tunisia",
"latitude": 35.864546,
"longitude": 10.5988045,
"street": "Hammem Sousse",
"zip": "4011"
},
"name": "Arabica Cafe",
"parking": {
"lot": 0,
"street": 0,
"valet": 0
},
"phone": "21770198",
"talking_about_count": 6,
"username": "arabiccafe",
"were_here_count": 66
}
In order to get these info, you can use a normal XHR request (or jQuery.ajax if you use jQuery) and make a GET request to this URL :
https://graph.facebook.com/arabiccafe?access_token={your_token}
You can generate a token following these directives.

Related

How to add post fields on the basis of result of elastic search

Actually i want to add "is_promoted" field in the response according to the result of elastic search if the "doc_count" is 1 then i have to fetch the id of the property and "is_promoted" flag from the actual result(Which you can see at the question).Its like a post filter in the elastic search. but i want add condition in the post filter. please see the current and expected output.
And below is the current output of the elastic query
{
"total_records": 32392,
"fetched_records": 3845,
"result": [
{
"key": "dp3w",
"doc_count": 343,
"centroid": {
"location": {
"lat": 41.919059987131064,
"lon": -87.71653202438385
},
"count": 343
}
},
{
"key": "djvw",
"doc_count": 1,
"centroid": {
"location": {
"lat": 33.49416188221888,
"lon": -82.0443208285174
},
"count": 1
}
},
{
"key": "9qhs",
"doc_count": 1,
"centroid": {
"location": {
"lat": 34.52696419113244,
"lon": -117.29711956000672
},
"count": 1
}
}
]
}
So i want to add field "is_promoted" if the "doc_count" is 1 and below is the expected output
{
"total_records": 32392,
"fetched_records": 3845,
"result": [
{
"key": "dp3w",
"doc_count": 343,
"centroid": {
"location": {
"lat": 41.919059987131064,
"lon": -87.71653202438385
},
"count": 343
}
},
{
"key": "djvw",
"doc_count": 1,
"is_promoted":true,
"centroid": {
"location": {
"lat": 33.49416188221888,
"lon": -82.0443208285174
},
"count": 1
}
},
{
"key": "9qhs",
"doc_count": 1,
"is_promoted":true,
"centroid": {
"location": {
"lat": 34.52696419113244,
"lon": -117.29711956000672
},
"count": 1
}
}
]
}
I used aggregation for that.
query.bool.minimum_should_match = 1;
aggQuery.zoomedin = {
filter: {
geo_bounding_box: {
location: {
top_left: {
lat: params.geo_bounding_box.location.nw.lat,
lon: params.geo_bounding_box.location.nw.lng
},
bottom_right: {
lat: params.geo_bounding_box.location.se.lat,
lon: params.geo_bounding_box.location.se.lng
}
}
}
},
aggregations: {
result: {
geohash_grid: {
field: "location",
precision: zoomLevel
},
"aggs": {
"centroid": {
"geo_centroid": { "field": "location" }
}
}
}
}
Below is the record structure in my elastic search. I hope it will help you to understand the senario
"hits": {
"total": 7967,
"max_score": 1,
"hits": [
{
"_index": "biproxi-test",
"_type": "listings",
"_id": "5126",
"_score": 1,
"_source": {
"address_line1": "Brandon Town Center Drive",
"address_line2": "USA",
"building_class": null,
"building_type": null,
"built_year": null,
"cap_rate": null,
"category": 1,
"city": "Brandon",
"country": "United States",
"county": "Hillsborough",
"floor_location": null,
"inplace_occupancy": null,
"land_size": 3,
"lease_type_id": null,
"lease_type": null,
"listing_group": "Retail",
"listing_type": [
1
],
"location": {
"lat": 27.937159,
"lon": -82.327498
},
"no_of_units": null,
"postal_code": "33511",
"price": 2185000,
"renovated_year": null,
"square_feet": null,
"state": "Florida",
"state_code": "FL",
"title": "3+- Acres at Brandon Town Center",
"status": 2,
"listing_image": "https://biproxi.s3.amazonaws.com/image/listing/5126/caf39154-fb42-483f-9320-9e9c394be66b.jpg",
"seller_id": "113157245308689129523",
"is_promoted": false
}
}, {
"_index": "biproxi-test",
"_type": "listings",
"_id": "5213",
"_score": 1,
"_source": {
"address_line1": "1909 N. Columbia Street",
"address_line2": "USA",
"building_class": null,
"building_type": null,
"built_year": "1996",
"cap_rate": null,
"category": 2,
"city": "Milledgeville",
"country": "United States",
"county": "Baldwin",
"floor_location": null,
"inplace_occupancy": null,
"land_size": null,
"lease_type_id": null,
"lease_type": null,
"listing_group": "Retail",
"listing_type": [
1
],
"location": {
"lat": 33.1086,
"lon": -83.25388
},
"no_of_units": null,
"postal_code": "31061",
"price": null,
"renovated_year": null,
"square_feet": null,
"state": "Georgia",
"state_code": "GA",
"title": "Milledge Village - 1 Space Remaining",
"status": 2,
"listing_image": "https://biproxi.s3.amazonaws.com/image/listing/5213/33d1cd5b-11a1-427d-8948-2e2db3d8e7f2.jpg",
"seller_id": "113157245308689129523",
"is_promoted": false
}
}
}]}
Okay, so, from the discussion in the direct comments under your OP I understand that you only want to add is_promoted field to some of the objects in the result array of the ES response, according to a certain condition.
What you need to do is very simple: loop through the result array, check the condition for each object and add the property.
for (const obj of elasticSearchResult.result) {
if (+obj.doc_count <= 1) {
obj['is_promoted'] = true;
}
}
I add the + sign in front of the obj.doc_count to ensure it's parsed to int and thus conducting a proper conditional comparison. The is_promoted property is added as an array key to ensure there are no compile or runtime errors of the sort of Property does not exist, since we create a new property in the object.
I don't know why do you use this aggregation functionality. You problem is purely JavaScript related and has nothing to do with ES or Node.js in particular.
P.S. This solution is based on the fact I understand your question correctly. Otherwise, please extend or improve your OP.

Retrieve a value from a script and replace a DIV with it

I am trying to retrieve from the code below the value of "city" which in this case is Bothell and use the text to replace a DIV in my HTML. This is the code:
$(document).ready(function() {
var f = function() {
realgeeks.analytics.send_activity({
"site_uuid": "09bce392-c259-4c5b-ba82-02547e30f980",
"property": {
"city": "**Bothell**",
"full_baths": 3,
"listing_status": "ACTIVE",
"year_built": 1984,
"zip": "98012",
"listing_days_on_market": 3,
"url": "http://www.bothellhomes.com/property/1265902/",
"sqft": "1306",
"tags": ["Snohomish", "Southeast Snohom",
"Thrashers Corner", "Parkshore", "Bothell",
"98012", "Parkshore Div 4", "1265902",
"Northshore"
],
"longitude": -122.204533,
"beds": 3,
"mls": "1265902",
"state": "WA",
"images": [
"https://property-media.realgeeks.com/40/8039f526bebf11225fda49555d1f4217.jpg",
"https://property-media.realgeeks.com/40/cd649b5ae431bec9fe4a5802a6520f5e.jpg",
"https://property-media.realgeeks.com/40/a43099b8b8b30772b019ac2aaea3460f.jpg"
],
"latitude": 47.830478,
"listing_price": "440000",
"type": "Single Family Residential",
"list_date": "2018-04-01T00:00:00+00:00",
"street_address": "18430 20th Dr SE"
},
"type": "property_viewed"
});
};
f();
$(document).on('fb-lead-login', f);
});
How would I go about doing this, knowing I don't have access to this block of code due to my web provider?

angularjs response data does not show in console

i have below code i but data not show in console log please help me i am new in angular.. AND how to show data in HTML
this.$http.get(properties.client+'/123')
.then(response => {
$scope.clientdata= response.data;
console.log($scope.clientdata.address);
});
address array dose not show in console log,i don't know why RESPONSE BELOW
[{ "_id": "123",
"__v": 1,
"history": [],
"address": {
"street_address": "adsf",
"state": "adsf",
"zip_code": "adsf",
"phone_number": "asdf",
"country": "ads",
"city": "asdf",
"site_name": "adsf",
"_id": "123123",
"geolocation": {
"coordinates": [],
"type": "Point"
},
"location": {
"latitude": null,
"longitude": null
},
"id": "5835baaa71a30ca8319b6e36"
},
"current_status": "Assigned",
"time": 0
}]
Your clientdata is an array as per the post, try
console.log($scope.clientdata[0].address);
HTML
{{clientdata[0].address}}
From the structure of your JSON data, clientdata is an array of objects and as of current, there is only one object in the array. So, in order to access the address property of the object, you will have to access it in this way
$scope.clientdata[0].address
and in HTML
{{clientdata[0].address._id}}
and rest of the address object properties in similar fashion.

Using ember-data with custom serializer

I have you could say a non standard json api. I'm trying to use ember-data with it so from my reading around I need to create a serializer. I tried to find article online explaining how to do this but haven't found anything useful. I tried looking through the ember guides but also found nothing. Here is an example of my api:
collection of data:
{
"data": [
{
"id": 14,
"name": "company name",
"slug": "company-name",
"detail": {
"data": {
"id": 10,
"address": "10000 sw 16th ct",
"city": "Hollywood",
"state": "Alabama"
}
},
"employees": {
"data": [
{
"id": 17,
"first_name": "Peter",
"last_name": "Griffin",
"email": "company-name#Griffin.co"
},
{
"id": 18,
"first_name": "Robert",
"last_name": "Gornitz",
"email": null
}
]
}
},
{
"id": 8,
"name": "company name",
"slug": "company-name",
"detail": {
"data": {
"id": 8,
"address": "1000 n university dr",
"city": "Fort Lauderdale",
"state": "West Virginia"
}
},
"employees": {
"data": [
{
"id": 15,
"first_name": "Peter",
"last_name": "Griffin"
},
{
"id": 16,
"first_name": "Peter",
"last_name": "Griffin"
}
]
}
}
]
}
Here is an item with its relationships:
{
"data": {
"id": 1,
"name": "company name",
"slug": "company-name",
"detail": {
"data": {
"id": 1,
"address": "1515 n university dr",
"city": "Miami",
"state": "Mississippi"
}
},
"employees": {
"data": [
{
"id": 1,
"first_name": "Peter",
"last_name": "Griffin",
"email": "peter#email.com"
},
{
"id": 2,
"first_name": "Peter",
"last_name": "Griffin",
"email": "peter#email.com"
}
]
}
}
}
Are there any good resources showing me how to do this? Or should I just not use ember-data?
Just some tips from my side using Ember Data. I believe that you either have to be able the adapt api or write a deserializer:
1. Root Key "data"
Ember expects the root key to be the name of the model (e.g. "company"). You can handle that easily by creating an application serializer and overwriting the extractArray and extractSingle method by grabbing the payload from the 'data' key instead of the model "typeKey".
2. Embedded Records
You can use the EmbeddedRecordsMixin. But for that you will have to skip the root key "data" in the embedded records and directly include them (e.g. "employees": [ { id: "2", ... }, ... ])
I'd have a look at the EmbeddedRecordsMixin for that:
http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html
http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html#method_normalize
Hope that helps a little.

Retrieve Youtube Tags using Jquery

I'm trying to figure out how to retrieve Youtube Tags and use them in my code behind, but I can't even seem to retrieve any information whatsoever. What would be the best way to retrieve tags with a delimiter like a , or a ; ?
var video_id='VA770wpLX-Q';
$.getJSON('http://gdata.youtube.com/feeds/api/videos/'+video_id+'?v=2&alt=jsonc',function(data,status,xhr){
alert(data.data.tags);
});
This is what the Json object looks like:
{
"apiVersion": "2.1",
"data": {
"id": "VA770wpLX-Q",
"uploaded": "2011-02-24T22:31:02.000Z",
"updated": "2012-04-08T21:37:06.000Z",
"uploader": "drdrevevo",
"category": "Music",
"title": "Dr. Dre - I Need A Doctor (Explicit) ft. Eminem, Skylar Grey",
"description": "Music video by Dr. Dre performing I Need A Doctor featuring Eminem and Skylar Grey (Explicit). © 2011 Aftermath Records",
"tags": ["Dr", "Dre", "Eminem", "New", "Song", "Skylar", "Grey", "GRAMMYs", "Dr.", "Need", "Doctor", "video", "Eazy", "N.W.A.", "NWA", "easy", "drdre", "and", "em"],
"thumbnail": {
"sqDefault": "http://i.ytimg.com/vi/VA770wpLX-Q/default.jpg",
"hqDefault": "http://i.ytimg.com/vi/VA770wpLX-Q/hqdefault.jpg"
},
"player": {
"default": "http://www.youtube.com/watch?v=VA770wpLX-Q&feature=youtube_gdata_player"
},
"content": {
"5": "http://www.youtube.com/v/VA770wpLX-Q?version=3&f=videos&app=youtube_gdata"
},
"duration": 457,
"aspectRatio": "widescreen",
"rating": 4.902695,
"likeCount": "430519",
"ratingCount": 441253,
"viewCount": 88270796,
"favoriteCount": 306556,
"commentCount": 270597,
"status": {
"value": "restricted",
"reason": "requesterRegion"
},
"restrictions": [{
"type": "country",
"relationship": "deny",
"countries": "DE"
}],
"accessControl": {
"comment": "allowed",
"commentVote": "allowed",
"videoRespond": "allowed",
"rate": "allowed",
"embed": "allowed",
"list": "allowed",
"autoPlay": "denied",
"syndicate": "allowed"
}
}
}
Youtube no longer supports "tag" functionality with it's API.

Categories

Resources