Get the list of users that liked a post - javascript

A friend of mine decided to run a sweepstakes on Instagram without giving much thought to how to get the full list of users that liked a post. He's saying he can just pick a random user from the available/visible list, but that wouldn't be fair, so I decided to step in.
The post in question, currently, has 1.4k likes.
First, I created a tiny script in JS to view, scroll down (to populate the list) and finally get the users that liked the post. This was troublesome to create, but it works. Then I realized I could not view all the users. While there are 1.4k users, I could only list 675 of them.
In the name of fairness, this is not enough. So I started digging more and examined the HTTP Requests made by the (Instagram) post page to the Instagram Graph API to load more users. This is what the URL looks like:
https://www.instagram.com/graphql/query/?query_id=SOME_ID&variables={\"shortcode\":\"SHORTCODE\",\"first\":20}
When I make a request to this URL, I get the following:
{
"data": {
"shortcode_media": {
"id": "SOME_ID",
"shortcode": "SHORTCODE",
"edge_liked_by": {
"count": 675,
"page_info": {
"has_next_page": false,
"end_cursor": "AQBPkM1xm2XgBx8ZQ8lR6GDsFAvQBx_Eqxg2NnTXN-GUPGhlpUa9_10UoMcJ6xNcIH4"
},
"edges": [{
"node": {
"id": "", // value omitted intentionally
"username": "", // value omitted intentionally
"full_name": "", // value omitted intentionally
"profile_pic_url": "", // value omitted intentionally
"is_verified": false,
"followed_by_viewer": false,
"requested_by_viewer": false
}
},
...
There's this ["edge_liked_by"]["count"] property and it is set to 675. I'm guessing this is a server-side restriction. When I increase the "first" parameter in the URL and make it greater than 675, it still returns 675 users.
Can I overcome this restriction and get the full list in any way?
Update: I've just tried the same thing with comments. The post has 11.8k comments and this is what the request returns:
{
"data": {
"shortcode_media": {
"edge_media_to_comment": {
"count": 11809,
"page_info": {
"has_next_page": true,
"end_cursor": "AQBV53OxNFkaHwJ6xjgHmlI-hwtpHCEeButMmGLwZJ_sjdyUy49gY_WZo1iH_aRcuAFOCzfrKPEktMaQLRjFVAsmQTincJpr4ZTITbTT1BZkJQ"
},
"edges": [{
"node": {
"id": "",
"text": "",
"created_at": ,
"owner": {
"id": "",
"profile_pic_url": "",
"username": ""
}
}
},
...
The exact count of the comments is 11809 and the request listed first 10259, but there's a next page. So I requested the next page and this is it:
{
"data": {
"shortcode_media": {
"edge_media_to_comment": {
"count": 11809,
"page_info": {
"has_next_page": false,
"end_cursor": null
},
"edges": [{
"node": {
"id": "",
"text": "",
"created_at": ,
"owner": {
"id": "",
"profile_pic_url": "",
"username": ""
}
}
},
...
This time it didn't return the remaining 1550 (11809 - 10259) users, but just 356 of them. And there's no next page. So there seems to be some inconsistencies. (Perhaps, there's a privacy issue that prevents some users to be listed?)

Related

Best way to update multiple attributes in nested state?

Just before I go about having to learn Redux or use Immer, I was wondering if anyone knew of a simple way to do this. I checked the React docs but I must be making a mistake somewhere, and need new sets of eyes on this.
I've got a users array of objects that is set to state {i.e. users, setUsers) , where each user object that has nested within it posts and concerts. Here's an example of one of them:
{
"id": 305,
"username": "L0V3MUSIC",
"email": "kanisha.hansen#bayer.co",
"posts": [
{
"id": 129,
"body": "PLEASE EMAIL IF YOU HAVE 4 TICKETS ALTOGETHER! MY DAUGHTERS LOVE HER -- THX ",
"for_sale": false,
"tickets": 4,
"concert_id": 51,
"user_id": 305
}
],
"concerts": [
{
"id": 51,
"date": "2023-07-22T00:00:00.000Z",
"location": "Brooklyn Steel",
"image": "https://i.imgur.com/SmFrzTC.jpg",
"artist_id": 37
}
]
},
I've also got concerts state holding an array of objects with the same information also and in the same way as above with users.
{
"id": 51,
"date": "2023-07-22T00:00:00.000Z",
"location": "Brooklyn Steel",
"image": "https://i.imgur.com/SmFrzTC.jpg",
"artist_id": 37,
"artist": {
"id": 37,
"name": "Adele",
"image": "https://i.imgur.com/zmGbfKS.jpg",
"genre": "Pop"
},
"posts": [
{
"id": 123,
"body": "2 tickets, $100 total OBO -- CHEAPEST YOU'LL EVER FIND FOR ADELE!!",
"for_sale": true,
"tickets": 2,
"concert_id": 51,
"user_id": 289
},
{
"id": 124,
"body": "3 tickets, $400 total OBO!",
"for_sale": true,
"tickets": 3,
"concert_id": 51,
"user_id": 289
},
{
"id": 129,
"body": "PLEASE EMAIL IF YOU HAVE 4 TICKETS ALTOGETHER! MY DAUGHTERS LOVE HER -- THX ",
"for_sale": false,
"tickets": 4,
"concert_id": 51,
"user_id": 305
}
],
"users": [
{
"id": 289,
"username": "onlineguy1",
"email": "su#cronin.name"
},
{
"id": 305,
"username": "L0V3MUSIC",
"email": "kanisha.hansen#bayer.co"
}
]
},
My issue is that I want to update a post that a user enters. I'd like to iterate either through users or through concerts, as I'm not sure which is best just yet given that both are 'symmetrical' in a sense. I don't want to have a posts state object though as I'm being graded on my ability to access users through concerts, and concerts through users.
currentUser is just the user that is currently logged in, and who would be the author of the created post. What I've tried to do a bunch of different ways is this: (here's my latest iteration)
if (response.status >= 200 && response.status <= 299) {
response.json().then((createdPost) => {
console.log('createdPost: ', createdPost);
const updatedPosts = currentUser.posts.map((eachPost) => {
if (eachPost.id === createdPost.id) {
return createdPost;
} else {
return eachPost;
}
});
console.log('updatedPosts: ', updatedPosts);
setCurrentUser(...currentUser, currentUser.posts: updatedPosts)
// FIGURE OUT HOW TO UPDATE THE STATE OF THE ABOVE
// THEN MAP THROUGH USERS AND UPDATE THAT USER WITH CURRENTUSER INSTEAD
});
setError([]);
setSuccess('Your post has been created!');
setSubmitted(true);
} else {
What I have above is updating the currentUser's posts and have an updated collection of the currentUser's post, and then ideally update the users state itself with this currentUser (and his updated posts) replacing currentUser (and his now outdated posts, given that they don't include the newly created post). But I've managed to confuse myself through the nesting and mapping and staring at this too long.
Is there a concise way to go about either updating the posts altogether then iterating through the user then updating users state, in a way that doesn't require redux or a plugin? Or is there a better way to go about handling this entirely? I'm assuming for sure that I'm being sloppy in getting this done so I'll take any steps in the right direction

Unable to get nested array of objects from json-server

I am trying to get array of objects from one of the nested JSON properties fields through the json-server, but I am getting 404 error.
When I access the URL in the browser 'http://localhost:4001/templates/5f105f243c076f3a82c95353' I get the JSON as mentioned in the db.json, but when I try to access this URL 'http://localhost:4001/templates/5f105f243c076f3a82c95353/fields' I am getting 404 error.
I believe from the db.json file, as fields array is a part of template so /fields followed by the base URL of the particular template (http://localhost:4001/templates/5f105f243c076f3a82c95353) should work but it is not working, please help me.
db.json file
{
"id": "5f105f243c076f3a82c95353",
"templateIdName": "DNIS Groups",
"templateDisplayName": "DNIS Groups Template",
"templateDescription": "Template for DNIS Groups",
"fieldCounter": 2,
"fields": [
{
"id": 1,
"fieldIdName": "OutageGroup",
"fieldDisplayName": "Outage Group",
"description": "Outage Group",
"type": "MultiList",
"values": [
{
"listValue": "2803",
"listDisplay": "Wire Down"
},
{
"listValue": "2804",
"listDisplay": "Streetlight Outage"
}
],
"initialValue": "2803",
"lockValue": "false",
"requireValue": "true",
"uniqueField": "true",
"autoFilter": "false",
"hideInList": "false",
"indexField": "true"
},
{
"id": 2,
"fieldIdName": "ProtectLinesGroups",
"fieldDisplayName": "Protect Lines Group",
"description": "Protect Lines Group",
"type": "MultiList",
"values": [
{
"listValue": "2814",
"listDisplay": "Cover Lines"
},
{
"listValue": "2815",
"listDisplay": "Voltage"
}
],
"initialValue": "2814",
"lockValue": "false",
"requireValue": "true",
"uniqueField": "false",
"autoFilter": "false",
"hideInList": "false",
"indexField": "false"
}
]
}
routes.json file
{
"/webservice/:clientId/dblookup/template": "/templates",
"/webservice/:clientid/dblookup/template/:id": "/templates/:id",
"/webservice/:clientid/dblookup/template/:id/fields": "/templates/:id/fields"
}
Actually JSON-Server don't have the provision to access the nested resources, it can only access resources which are defined as the top level properties in the file, in this example the top level property will be templates and I can access that using http://localhost:4001/templates but I cannot access the nested property values here as http://localhost:4001/templates/2/values it gives 404 not found error.

Integrating Plaid with Salesforce

I am trying to integrate Plaid API with salesforce in a visualforce page and I have done all the procedures my only problem is that while the response is being returned there are no transactions in the response returned is there any particular parameter that I need to add for the transactions to appear in the response.
const request: TransactionsGetRequest = {
client_id: client_id,
secret: secret
access_token: access_token
start_date: '2018-01-01',
end_date: '2020-02-01',
options: {
count: 250,
offset: 0,
}
Response Example
{
"accounts": [
{
"account_id": "BxBXxLj1m4HMXBm9WZZmCWVbPjX16EHwv99vp",
"balances": {
"available": 110,
"current": 110,
"iso_currency_code": "USD",
"limit": null,
"unofficial_currency_code": null
},
"mask": "0000",
"name": "Plaid Checking",
"official_name": "Plaid Gold Standard 0% Interest Checking",
"subtype": "checking",
"type": "depository"
}
],
"transactions": [],
"item": {
"available_products": [
"balance",
"credit_details",
"identity",
"investments"
],
"billed_products": ["assets", "auth", "liabilities", "transactions"],
"consent_expiration_time": null,
"error": null,
"institution_id": "ins_3",
"item_id": "eVBnVMp7zdTJLkRNr33Rs6zr7KNJqBFL9DrE6",
"webhook": "https://www.genericwebhookurl.com/webhook"
},
"total_transactions": 0,
"request_id": "45QSn"
}
This is the response containing the number of transactions still I don't get any transactions when I use API calls in salesforce.
Thank you for posting your query. I think the issue is just that the dates you're using for your test query are too old for the Sandbox test environment -- I don't think the Sandbox loads transaction data for that far in the past. Can you try with a set of dates from this year?
Edit: Or it could be a timing issue / transactions haven't loaded yet, which seems likely given that it works in Postman for you but not in Salesforce.

How do I access values in a d3 json file with nested array objects

Previously I was using a json file with the following format:
[{"lat":43.788458853157117,"lng":-79.282781549043008,"category":"volunteer","name":"Rita","url":"", "description":"xxx is a member of 13"},{"lat":43.7,"lng":-79.4,"category":"organization","name":"TCAN","url":"http://tcan.ca","description":"Lorem ipsum"}]
Now I am attempting to generate the json file from a Drupal site and am getting the following structure. How can I reference the lowest level fields. I have looked at examples using d3.net but have not found any that apply.
{
"organizations": [
{
"member": {
"field_category": "organization",
"body": "A network of organizations in Toronto devoted to climate change mitigation and adaptation.",
"URL": "xxx.ca",
"title": "Toronto Climate Action Network",
"field_lat": 43.7,
"field_long": -79.4
}
},
{
"member": {
"field_category": "abc",
"body": "xxx.",
"URL": "",
"title": "yyy",
"field_lat": 43.7,
"field_long": -79.28
}
}
]
}
Assuming that your data is stored in the variable data:
var bottom = data.organizations.map(function(d) { return d.member; });

jQuery inserting JSON value to element with specific class

I'm have a little trouble with some jQuery I have been trying to put together today.
Basically what I am trying to achieve is to dynamically have prices inserted into a price button on my page by reading from a JSON feed.
The idea is that there is an empty span that will contain the price. I have given all of the price spans the class .getPriceNew. Each span also has an id which is equal to the SKU number for the item like this <span class="getPriceNew" id="123456"></span>.
The mechanic is that for each span that has the class .getPriceNew the JSON will be queried for the information with the SKU id used as part of the query string.
Here is an example of the code i have tried
jQuery
$(".getPriceNew").each(function() {
var sku = $(this).attr("id");
var priceNew = $.getJSON('/api/MyApi.svc/GetProductBySku/'+sku , function(data) {
return(data.Variants[0].Price);
});
$(this).html("€"+priceNew);
})
HTML
<span class="getPriceNew" id="123456"></span>
<span class="getPriceNew" id="789123"></span>
<span class="getPriceNew" id="456789"></span>
<span class="getPriceNew" id="654321"></span>
JSON Example
This is what a single item from the JSON feed would look like - I have filtered it a little
/api/MyApi.svc/GetProductBySku/123456
Updated with valid JSON
{
"Age": {
"Description": "Age 18+",
"Thumbnail": "http://someurl.com/productImages/assets/img//icon18.gif"
},
"Barcode": {
"Barcode": "5026555408684"
},
"Description": "HTML",
"Id": 12214,
"Packshots": [
"http://someurl.com/productImages/914383/1min.jpg",
"http://someurl.com/productImages/914383/2med.jpg",
"http://someurl.com/productImages/914383/3max.jpg"
],
"Pegis": [],
"Platform": {
"Button": "Format",
"ID": 0
},
"Publisher": {
"Description": null
},
"Release": "/Date(1364252400000+0100)/",
"Screenshots": [],
"Title": "Product Title",
"Variants": [
{
"Id": 22488,
"MaxOrderQuantity": 3,
"Presellable": true,
"Price": 49.97,
"Sku": 914383,
"Type": {
"Description": "Pre-Order"
}
}
],
"Vendor": {
"Description": "Take Two Interactive Software"
},
"VideoHTML": "HTML",
"status": {
"Response": "product found",
"Success": true
}
}
I would love some help on this as I am really scratching my newbie head at this stage. I have managed to have console.log output the prices to the log but when I try and insert them back into the spans all I get is [object] [Object].
You are doing
$(".getPriceNew").each(function() {
var sku = $(this).attr("id");
var priceNew = $.getJSON('/api/MyApi.svc/GetProductBySku/'+sku , function(data) {
return(data.Variants[0].Price);
});
$(this).html("€"+priceNew);
})
getJSON returns a jqXHR object, which is not what you need. Try this:
$(".getPriceNew").each(function() {
var sku = $(this).attr("id");
// Save a refference to this span.
var thisSpan = $(this);
$.getJSON('/api/MyApi.svc/GetProductBySku/'+sku , function(data) {
// Request complete, NOW we can use the data we got!
thisSpan.html("€"+data.Variants[0].Price);
});
})
The callback is where you want to use the data you get from your AJAX calls. All AJAX methods ($.ajax, $.get, $.post, $.getJSON, etc) will return a jqXHR object.
I think your javascript code is correct but your Json output has two errors:
1: "Description":"Some HTML Description here, <- you forgot the closing quote
2: "ID":0}, <- delete the closing brace
So your Json will result like this:
{
"Age": {
"Description": "Age 18+",
"Thumbnail": "http://url.com/image.gif"
},
"Barcode": {
"Barcode": "4876416541647"
},
"Description": "Some HTML Description here",
"Id": 12214,
"Packshots": [
"http: //url.com/productImages/914383/1min.jpg",
"http: //http: //url.com/2med.jpg",
"http: //http: //url.com/3max.jpg"
],
"ID": 0,
"Publisher": {
"Description": null
},
"Release": "/Date(1364252400000+0100)/",
"Screenshots": [],
"Title": "Titleoftheproduct",
"Variants": [
{
"Id": 22488,
"MaxOrderQuantity": 3,
"Presellable": true,
"Price": 49.97,
"Sku": 914383,
"Type": {
"Description": "Pre-Order"
}
}
],
"Vendor": {
"Description": "Vendorname"
},
"VideoHTML": "<iframewidth="725"height="408"src="http: //www.youtube.com/embed/videoseries?list=PLofwA47XDv2_KnfUY52_8mlWg0iUEv8ci"frameborder="0"allowfullscreen></iframe>",
"status": {
"Response": "productfound",
"Success": true
} }
now your code
data.Variants[0].Price
will return 49.97
to validate Json you can paste it into http://jsonlint.com/ i think is very useful
Hope this helps

Categories

Resources