How do I get local business results using google maps API - javascript

Is there any google/Yahoo/Bing API which gives local business results based on a ZIP/GeoCode of a location? If yes, please let me know.
If Google Maps has such service, please let me know what where do I get a reference regarding that?

Disclosure: I work at SerpApi.
Is there any google/Yahoo/Bing API which gives local business results based on a ZIP/GeoCode of a location?
Yes, you can use SerpApi to get local business results based on ZIP, query, or GPS coordinates: https://serpapi.com/playground?engine=google_maps&q=coffee+Austin+TX+78747&type=search
Sample response
{
"local_results": [
{
"position": 1,
"title": "The Standard Grill",
"data_id": "0x89c259c06677ef37:0x5707f22fe7137aa2",
"gps_coordinates": {
"latitude": 40.7406697,
"longitude": -74.0079042
},
"place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c259c06677ef37%3A0x5707f22fe7137aa2%218m2%213d40.7406697%214d-74.0079042&engine=google_maps&google_domain=google.com&token=f01cbc346c0db944&type=place",
"rating": 4.1,
"reviews": 840,
"price": "$$$",
"type": "Bar & grill",
"address": "848 Washington St, New York, NY 10014",
"hours": "Open until 11:30 PM",
"phone": "(212) 645-4100",
"website": "http://www.thestandardgrill.com/",
"description": "Trendy, upscale American dining. Trendy, clubby, hotel-set American bistro under the High Line with sidewalk tables & lively bar.",
"editorial_reviews": {
"summary": "Where To Eat On Christmas Day In New York City",
"link": "https://www.forbes.com/sites/melissakravitz/2019/12/13/christmas-dinner-new-york-city/"
},
"thumbnail": "https://lh5.googleusercontent.com/p/AF1QipMGM_4u4iQcrdRZApFFIinDga-cb0rXu79aFxvv=w125-h92-k-no"
},
{
"position": 2,
"title": "Rockmeisha - Sake & Grill",
"data_id": "0x89c259938c3a05cb:0xa1b2fe3b945a853d",
"gps_coordinates": {
"latitude": 40.732638,
"longitude": -74.00237299999999
},
"place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c259938c3a05cb%3A0xa1b2fe3b945a853d%218m2%213d40.732638%214d-74.00237299999999&engine=google_maps&google_domain=google.com&token=8bcfdeb90a3d1f1a&type=place",
"rating": 4.3,
"reviews": 102,
"price": "$$",
"type": "Tapas restaurant",
"address": "11 Barrow St, New York, NY 10014",
"hours": "Opens at 6:00 PM",
"phone": "(212) 675-7775",
"website": "http://rockmeisha-izakaya.business.site/",
"description": "Japanese drink-&-snack joint. Traditional Japanese drinking establishment pairing its sake & beer with ramen & small plates.",
"editorial_reviews": {
"summary": "25 Exemplary Fried Chicken Dishes Around NYC",
"link": "https://ny.eater.com/maps/nyc-fried-chicken-best"
},
"thumbnail": "https://lh5.googleusercontent.com/p/AF1QipNA8eJZ-VZxHIV43490yYZCnjDbBbYUA9wiH_Lq=w122-h92-k-no"
}
]
}
You can use Node.js wrapper
const { GoogleSearchResults } = require('google-search-results-nodejs')
const client = new GoogleSearchResults("API_KEY")
const parameters = {
engine: "google_maps",
type: "search",
google_domain: "google.com",
q: "NY 10014 grill",
};
function onResponse(data) {
console.log(data.local_results[0])
}
client.json(parameters, onResponse)
If Google Maps has such service, please let me know what where do I get a reference regarding that?
https://serpapi.com/maps-local-results

Google does have that, you can even check few sample implementations:
http://code.google.com/apis/ajaxsearch/local.html

Related

API call with Axios filtering response.data

I want to get the newest 8 products depend on product's date. I can get the whole products array and filter it as you see below:
const newestProducts= [];
axios.get("http://localhost:3003/products").then(response => {
let products = response.data.sort(function(a, b) {
return new Date(b.date) - new Date(a.date);
});
newstProducts = product.slice(0,7)
});
but this will be so bad if I have thousands of product, and I just need to get the newest 8 Products only
I thought about adding ?_limit=8 to the call
axios.get("http://localhost:3003/products?_limit=8").then{...}
but this also doesn't work propersly as you know because it gets me the only top 8 products of the array
Is there any way to filter the products before I get it from the server or I MUST store them all in var and then filter them
The Json File
"categories": [
{
"id": 9,
"category": "bathroom",
"date": "2020/8/3",
"name": "ullam basin mixer",
"price": 160,
"img_1": "rim_mixer_01.jpg",
"img_2": "rim_mixer_02.jpg",
"rating": 4.5,
"description": "MARMO is a complete series made of 72 models, with different shapes and sizes for different functions, that keeps uncompromised its elegant beauty. This is a Demo Online Store."
},
{
"id": 10,
"category": "bathroom",
"date": "2020/8/19",
"name": "gravida bathtub",
"price": 2100,
"img_1": "inbani_bathtub_01.jpg",
"img_2": "inbani_bathtub_02.jpg",
"rating": 4,
"description": "A young company with a wealth of experience. created in 2004, inbani has evolved into a leader in innovation thanks to a conviction to create products which truly benefit the well-being of the customer. This is a Demo Online Store. No orders shall be fulfilled."
},
{
"id": 11,
"category": "bathroom",
"date": "2020/9/9",
"name": "vulputate mixer",
"price": 300,
"img_1": "marmo_mixer_01.jpg",
"img_2": "marmo_mixer_02.jpg",
"description": "MARMO is a complete series made of 72 models, with different shapes and sizes for different functions, that keeps uncompromised its elegant beauty. This is a Demo Online Store."
},
{
"id": 12,
"category": "bathroom",
"date": "2018/7/17",
"name": "aliquam veneatis bathtub",
"price": 2580,
"img_1": "sa_oche_01.jpg",
"img_2": "sa_oche_02.jpg",
"description": "Its oval, elliptical design with the incongruent walls invokes an avant-garde atmosphere in the bathroom."
},
{
"id": 13,
"category": "kitchen",
"date": "2020/3/13",
"name": "quisque teapot",
"price": 240,
"img_1": "theo_teapot_01.jpg",
"img_2": "theo_teapot_02.jpg",
"description": "Theo Teapot is a Scandinavian-Japanese teapot made from stoneware and bamboo, designed by Unit 10 Design for Stelton. This is a Demo Online Store. No orders shall be fulfilled."
},
{
"id": 14,
"category": "kitchen",
"date": "2020/2/12",
"name": "creamic teapot",
"price": 60,
"img_1": "cer_teapot_01.jpg",
"img_2": "cer_teapot_02.jpg",
"rating": 3.9,
"description": "Matte ceramic tea pot comes with integrated and removable metal tea infuser. Capacity 700 ml (2.96 cups). Dishwasher safe. This ceramic teapot has a white matte finish, coupled with a square shape and curved lines."
},
{
"id": 15,
"category": "kitchen",
"date": "2019/2/1",
"name": "bottle grinders",
"price": 30,
"img_1": "bottle_gringer_01.jpg",
"img_2": "bottle_gringer_02.jpg",
"rating": 4.8,
"description": "Bottle Grinders is a minimal, timeless salt and pepper mill set designed by Norm.Architects for Menu. Steering away from the predictable grinder, the Norm Bottle Grinder is not what you expect to see in a salt and pepper grinder. The form, shaped more like a bottle, cleverly tricks the user to encourage a more playful and experimental interaction with the product. This is a Demo Online Store. No orders shall be fulfilled. Purchase this product"
},
{
"id": 16,
"category": "lighting",
"date": "2020/1/3",
"name": "commodo blown lamp",
"price": 275,
"img_1": "tradition_blown_01.jpg",
"img_2": "tradition_blown_02.jpg",
"description": "Blown lamp SW3 & SW4 by &tradition is a mouth-blown pendant lamp with a quilted pattern, it comes in a translucent variant with a silver lustre or in a opal white version. Blown lamp is fitted with a powder-coated metal suspension. This is a Demo Online Store. No orders shall be fulfilled."
},
{
"id": 17,
"category": "lighting",
"date": "2020/6/9",
"name": "spot table",
"price": 100,
"img_1": "spot_lamp_01.jpg",
"img_2": "spot_lamp_02.jpg",
"rating": 3.4,
"description": "Set the stage. The Spot lamp is a lively, versatile addition to your room. This is a Demo Online Store. No orders shall be fulfilled."
}
]
The problem is not in API Calling... To enhance the performance you have to refractor the DATABASE REQUEST in the backend to get the last 8 products only.
Note:
You make this through the query you send to the database in the controller (ROUTE ) in the backend

Referencing JSON data result from API Request - Javascript

I'll start out by saying that I am a pretty new web developer, so I apologize if this is overly basic... I just couldn't find it anywhere on Google. I'm receiving JSON data back from an API call to omdb, and I am unsure how to reference a line in the data Specifically, I am trying to reference the Rotten Tomatoes Value, and this needs to be repeatable for any movie I search. I started by storing the response in JSON and then working through each item I need:
var body = JSON.parse(body);
console.log("Title: " + body.Title);
console.log("Release Year: " + body.Year);
console.log("IMdB Rating: " + body.imdbRating);
console.log("Country: " + body.Country);
console.log("Language: " + body.Language);
console.log("Plot: " + body.Plot);
console.log("Actors: " + body.Actors);
console.log("Rotten Tomatoes Rating: " + body.Ratings.????RottenTomatoes???);
It's just the Rotten Tomatoes Value Line I can't figure out! Everything else works. To clarify, this is just a JSON referencing issue I cannot figure out.
{
"Title": "Anastasia",
"Year": "1997",
"Rated": "G",
"Released": "21 Nov 1997",
"Runtime": "94 min",
"Genre": "Animation, Adventure, Drama",
"Director": "Don Bluth, Gary Goldman",
"Writer": "Susan Gauthier (screenplay), Bruce Graham (screenplay), Bob Tzudiker (screenplay), Noni White (screenplay), Eric Tuchman (animation adaptation)",
"Actors": "Meg Ryan, John Cusack, Kelsey Grammer, Christopher Lloyd",
"Plot": "The last surviving child of the Russian Royal Family joins two con men to reunite with her grandmother, the Dowager Empress, while the undead Rasputin seeks her death.",
"Language": "English, Russian, French",
"Country": "USA",
"Awards": "Nominated for 2 Oscars. Another 10 wins & 21 nominations.",
"Poster": "https:\/\/images-na.ssl-images-amazon.com\/images\/M\/MV5BNGJiNWFlYTMtZTBiZi00ZTVmLWJmZmMtNzEzYzZjNzYzZmRmXkEyXkFqcGdeQXVyNTA4NzY1MzY#._V1_SX300.jpg",
"Ratings": [
{
"Source": "Internet Movie Database",
"Value": "7.1\/10"
},
{
"Source": "Rotten Tomatoes",
"Value": "85%"
},
{
"Source": "Metacritic",
"Value": "59\/100"
}
],
"Metascore": "59",
"imdbRating": "7.1",
"imdbVotes": "94,074",
"imdbID": "tt0118617",
"Type": "movie",
"DVD": "16 Nov 1999",
"BoxOffice": "N\/A",
"Production": "20th Century Fox",
"Website": "N\/A",
"Response": "True"
}
The Rotten tomatoes value is in the 3rd element of the array. Array indexes start at 0. Therefore, what you need is body.Ratings[2].Value.
If the order of the Ratings array is unpredictable, use filter function as below.
//If the order of the source array is unpredictable
//use filter
var rtValue = body.Ratings.filter(function(source) {
return source.Source === "Rotten Tomatoes";
}).Value;
That's because it is an array inside an object. body.Ratings[0]. You are referencing the spot of an array. Definitely look into arrays.
"Ratings": [ { "Source": "Internet Movie Database", "Value": "7.1/10" }, { "Source": "Rotten Tomatoes", "Value": "85%" }, { "Source": "Metacritic", "Value": "59/100" } ]
See the [ square brackets ] Each object inside {} can be referenced with an integer inside [0], [1] etc.
Look at some online tutorials. www.w3schools.com/js is a great place to start

Extract strings from JSON as array in PHP [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have the following JSON from Google API and i want to extract cse_image -> src and use it in PHP array as arr[0] for first , arr[1] for second and so on.
{
"kind": "customsearch#search",
"url": {
"type": "application/json",
"template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
},
"queries": {
"nextPage": [
{
"title": "Google Custom Search - Gravity Falls",
"totalResults": "13600",
"searchTerms": "Gravity Falls",
"count": 2,
"startIndex": 4,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "005215763543692940433:2hdsc4__avm",
"filter": "0",
"disableCnTwTranslation": "disable"
}
],
"request": [
{
"title": "Google Custom Search - Gravity Falls",
"totalResults": "13600",
"searchTerms": "Gravity Falls",
"count": 2,
"startIndex": 2,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "005215763543692940433:2hdsc4__avm",
"filter": "0",
"disableCnTwTranslation": "disable"
}
],
"previousPage": [
{
"title": "Google Custom Search - Gravity Falls",
"totalResults": "13600",
"searchTerms": "Gravity Falls",
"count": 2,
"startIndex": 1,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "005215763543692940433:2hdsc4__avm",
"filter": "0",
"disableCnTwTranslation": "disable"
}
]
},
"context": {
"title": "Gravity Falls"
},
"searchInformation": {
"searchTime": 0.269451,
"formattedSearchTime": "0.27",
"totalResults": "13600",
"formattedTotalResults": "13,600"
},
"items": [
{
"kind": "customsearch#result",
"title": "Gravity Falls Apparel - Gravity Falls Wiki",
"htmlTitle": "\u003cb\u003eGravity Falls\u003c/b\u003e Apparel - \u003cb\u003eGravity Falls\u003c/b\u003e Wiki",
"link": "http://gravityfalls.wikia.com/wiki/Gravity_Falls_Apparel",
"displayLink": "gravityfalls.wikia.com",
"snippet": "Gravity Falls apparel are officially sold clothes. On December 11, 2012 \nWeLoveFine.com released...",
"htmlSnippet": "\u003cb\u003eGravity Falls\u003c/b\u003e apparel are officially sold clothes. On December 11, 2012 \u003cbr\u003e\nWeLoveFine.com released...",
"cacheId": "6Uh7-hm1BKoJ",
"formattedUrl": "gravityfalls.wikia.com/wiki/Gravity_Falls_Apparel",
"htmlFormattedUrl": "\u003cb\u003egravityfalls\u003c/b\u003e.wikia.com/wiki/\u003cb\u003eGravity\u003c/b\u003e_\u003cb\u003eFalls\u003c/b\u003e_Apparel",
"pagemap": {
"cse_image": [
{
"src": "http://img3.wikia.nocookie.net/__cb20130410025818/gravityfalls/images/thumb/5/54/Welovefine_rainbow_gnome.jpg/500px-Welovefine_rainbow_gnome.jpg" //This as arr[0]
}
],
"cse_thumbnail": [
{
"width": "225",
"height": "225",
"src": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcS6kUI6yrCQkhX45BaaylTdDWb9tKvUf2OxwXJJv5NONxG1f0o09YerhB9j"
}
],
"metatags": [
{
"viewport": "width=device-width, initial-scale=1.0, user-scalable=yes",
"fb:app_id": "112328095453510",
"og:type": "article",
"og:site_name": "Gravity Falls Wiki",
"og:title": "Gravity Falls Apparel",
"og:description": "Gravity Falls apparel are officially sold clothes. On December 11, 2012 WeLoveFine.com released the first official Gravity Falls merchandise. The same day they launched a Gravity Falls T-shirt design contest which was judged by Alex Hirsch and Michael Rianda. The Grand prize winner received up to $2,000, with several runners up receiving various prizes on top of their own designs becoming part of the online store.",
"og:url": "http://gravityfalls.wikia.com/wiki/Gravity_Falls_Apparel",
"og:image": "http://img3.wikia.nocookie.net/__cb20130410025818/gravityfalls/images/thumb/5/54/Welovefine_rainbow_gnome.jpg/500px-Welovefine_rainbow_gnome.jpg",
"apple-itunes-app": "app-id=623705389"
}
]
}
},
{
"kind": "customsearch#result",
"title": "Gravity Falls, Oregon - Gravity Falls Wiki",
"htmlTitle": "\u003cb\u003eGravity Falls\u003c/b\u003e, Oregon - \u003cb\u003eGravity Falls\u003c/b\u003e Wiki",
"link": "http://gravityfalls.wikia.com/wiki/Gravity_Falls,_Oregon",
"displayLink": "gravityfalls.wikia.com",
"snippet": "Gravity Falls, Oregon is a mysterious, sleepy, small town in Central Oregon, \nwhere there are many supernatural occurrences. It was founded by Quentin ...",
"htmlSnippet": "\u003cb\u003eGravity Falls\u003c/b\u003e, Oregon is a mysterious, sleepy, small town in Central Oregon, \u003cbr\u003e\nwhere there are many supernatural occurrences. It was founded by Quentin ...",
"cacheId": "le0YqUje3GYJ",
"formattedUrl": "gravityfalls.wikia.com/wiki/Gravity_Falls,_Oregon",
"htmlFormattedUrl": "\u003cb\u003egravityfalls\u003c/b\u003e.wikia.com/wiki/\u003cb\u003eGravity\u003c/b\u003e_\u003cb\u003eFalls\u003c/b\u003e,_Oregon",
"pagemap": {
"cse_image": [
{
"src": "http://img2.wikia.nocookie.net/__cb20120526133929/gravityfalls/images/thumb/f/fd/S1e1_gravity_falls_oregon_map.jpg/500px-S1e1_gravity_falls_oregon_map.jpg" // This as arr[1]
}
],
"videoobject": [
{
"thumbnail": "http://img2.wikia.nocookie.net/__cb20140905002344/video151/images/thumb/e/ec/Gravity_Falls_-_Referencias_Interesantes/300px-Gravity_Falls_-_Referencias_Interesantes.jpg",
"duration": "01:47"
}
],
"cse_thumbnail": [
{
"width": "299",
"height": "168",
"src": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTEsgxZQQYbR400fXDcbDafk6y5Jr9wLjy7ZAV7F3sfBccdhkGnwfiNlPA"
}
],
"metatags": [
{
"viewport": "width=device-width, initial-scale=1.0, user-scalable=yes",
"fb:app_id": "112328095453510",
"og:type": "article",
"og:site_name": "Gravity Falls Wiki",
"og:title": "Gravity Falls, Oregon",
"og:description": "Gravity Falls, Oregon is a mysterious, sleepy, small town in Central Oregon, where there are many supernatural occurrences. It was founded by Quentin Trembley, It's where Stan Pines lives and runs the Mystery Shack, a tourist trap which overcharges unlucky visitors for a glimpse at the world's most bizarre museum. Twin siblings Dipper and Mabel Pines are sent to stay with Stan for the summer, which leads them to discover the different yet curious wonders of Gravity Falls. Gravity Falls...",
"og:url": "http://gravityfalls.wikia.com/wiki/Gravity_Falls,_Oregon",
"og:image": "http://img2.wikia.nocookie.net/__cb20120526133929/gravityfalls/images/thumb/f/fd/S1e1_gravity_falls_oregon_map.jpg/500px-S1e1_gravity_falls_oregon_map.jpg",
"apple-itunes-app": "app-id=623705389"
}
]
}
}
]
}
Language: PHP
I want to extract JSON using PHP then access it using
arr[0]:http://img3.wikia.nocookie.net/__cb20130410025818/gravityfalls/images/thumb/5/54/Welovefine_rainbow_gnome.jpg/500px-Welovefine_rainbow_gnome.jpg
arr[1]:http://img2.wikia.nocookie.net/__cb20120526133929/gravityfalls/images/thumb/f/fd/S1e1_gravity_falls_oregon_map.jpg/500px-S1e1_gravity_falls_oregon_map.jpg
How can i do this with json_decode or any other similar method
$data = json_decode($string, true);
echo $data['items'][0]['pagemap']['cse_image'][0]['src'];
echo $data['items'][1]['pagemap']['cse_image'][0]['src'];

Google News Api custom search

I have this java script in my html file....I have a keyword search in my webpage, and I want to pass the keyword search to the API. This is what I currently have: Not sure where I am going wrong that it is not producing any search results.
where I have
CNN
in the code, this is where my search variable should be passed...
<script type="text/javascript">
google.load('search', '1');
function OnLoad()
{
var customSearchControl = new google.search.CustomSearchControl('CNN');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_
CSE_RESULTSET);
customSearchControl.draw('cse');
customSearchControl.execute("$q");
}
google.setOnLoadCallback(OnLoad);
// tell the searcher to draw itself and tell it where to attach
// create a drawOptions object
var drawOptions = new google.search.DrawOptions();
// tell the searcher to draw itself in tabbed mode
drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
searchControl.draw(document.getElementById("content"),drawOptions);
searchControl.addSearcher(new google.search.NewsSearch());
}
google.setOnLoadCallback(OnLoad);
</script>
You can use a third party solution like this one: https://serpapi.com/news-results
It works in a very similar way as the Google regular search, just pass the tbm=nws to your url.
https://serpapi.com/search.json?q=Trump&tbm=nws&location=Dallas&hl=en&gl=us
Results:
{
...
"news_results": [
{
"position": 1,
"title": "Trump blasts Sessions over indictments of two of his earliest ...",
"link": "https://www.cnn.com/2018/09/03/politics/donald-trump-jeff-sessions-justice-department/index.html",
"source": "CNN",
"date": "4 hours ago",
"snippet": "(CNN) President Donald Trump on Monday blasted his Attorney General Jeff Sessions and lamented the indictments of two lawmakers who ...",
"thumbnail": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSCv3eR2GkOR3WgDNTd4LqT77Bteu_ScA8NUFKcEYU1HskYXHXrnse-GnG0SN78_uUgM1k0nIQV"
},
{
"position": 2,
"title": "Trump accuses Sessions of hurting Republican congressional races",
"link": "https://www.reuters.com/article/us-usa-trump-sessions/trump-accuses-sessions-of-hurting-republican-congressional-races-idUSKCN1LJ231",
"source": "Reuters",
"date": "3 hours ago"
},
{
"position": 3,
"title": "Trump steams at Attorney General Jeff Sessions, reigniting his attacks",
"link": "https://abcnews.go.com/Politics/trump-steams-attorney-general-jeff-sessions-reigniting-attacks/story?id=57579418",
"source": "ABC News",
"date": "3 hours ago"
},
{
"position": 4,
"title": "Trump slams Sessions on Twitter, says AG is hurting GOP in midterms",
"link": "http://www.foxnews.com/politics/2018/09/03/trump-slams-sessions-on-twitter-says-ag-is-hurting-gop-in-midterms.html",
"source": "Fox News",
"date": "4 hours ago"
},
{
"position": 5,
"title": "Trump blasts Sessions over charges against GOP congressmen ...",
"link": "https://www.politico.com/story/2018/09/03/donald-trump-jeff-sessions-tweet-806298",
"source": "Politico",
"date": "5 hours ago"
},
...
],
...
}
I have the same issue and I think that the problem is these specialized CSEs have been 'deprecated' since 2010 ( see http://code.google.com/apis/websearch/) and now they just don't work. The new ones that do work are for general web search and image search. You can probably restrict the web search one to the CNN site if that's your goal. See What are the alternatives now that the Google web search API has been deprecated?

Facebook Feed on web page infinte scrolling

I am trying to use this plugin to create an infinite scroll effect for Facebook feeds, now I get access to the feed I need through the graph api (fan page wall posts) and I limit it to 10, and even so Facebook supplies a next and previous links to the next or previous 10 posts in the actual json data, but I just can't seem to get this plugin working with it.
Heres an example of the json data:
{
"data": [
{
"id": "393459637370574_326418557474553",
"from": {
"category": "Consulting/business services",
"name": "Global Georgia",
"id": "393459637370574"
},
"to": {
"data": [
{
"name": "Global Georgia Tour",
"start_time": "2012-12-05",
"location": "Republic of Georgia",
"id": "297926606990415"
}
]
},
"message": "What a lovely trip it was!",
"picture": "http://photos-a.ak.fbcdn.net/hphotos-ak-snc7/205700_468134469903090_2092776360_s.jpg",
"link": "https://www.facebook.com/photo.php?fbid=468134469903090&set=oa.462645617136057&type=1&relevant_count=4",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif",
"privacy": {
"value": ""
},
"type": "photo",
"object_id": "468134469903090",
"created_time": 1359555861,
"updated_time": 1359555861,
"likes": {
"data": [
{
"name": "Mareleen du Plessis",
"id": "1382224862"
}
],
"count": 1
},
"comments": {
"count": 0
}
},
{
"id": "393459637370574_333589073411971",
"from": {
"category": "Consulting/business services",
"name": "Global Georgia",
"id": "393459637370574"
},
"story": "Global Georgia shared a link.",
"story_tags": {
"0": [
{
"id": "393459637370574",
"name": "Global Georgia",
"offset": 0,
"length": 14,
"type": "page"
}
]
},
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQCwYiOOZnd4DK5_&w=90&h=90&url=http\u00253A\u00252F\u00252Frsa.mfa.gov.ge\u00252FuniInc.php\u00253Fmode\u00253Dimg\u002526src_jpg\u00253Dfiles\u00252Frsa\u00252FPresentation_Credentials_to_President_Jacob_Zuma_of_South_Africa-29.01.2013.jpg\u002526im_new_w\u00253D200",
"link": "http://rsa.mfa.gov.ge/index.php?lang_id=ENG&sec_id=913&info_id=16905",
"name": "News - Embassy of Georgia to the Republic of South Africa",
"caption": "rsa.mfa.gov.ge",
"description": "On January 2013, in Pretoria, the firstAmbassador Extraordinary and Plenipotentiary of Georgia in the Republic of South Africa, Mr Beka Dvali presented his credentials to the President of the Republic of South Africa, H.E. Mr Jacob Zuma. ",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
"privacy": {
"value": ""
},
"type": "link",
"status_type": "shared_story",
"created_time": 1359550985,
"updated_time": 1359550985,
"likes": {
"data": [
{
"name": "Ivan A Meyer",
"id": "100000016287990"
},
{
"name": "Amanda Aldum",
"id": "779374234"
},
{
"name": "Cazz Bouwer",
"id": "100001702505460"
},
{
"name": "Gigi Mikeladze",
"id": "100004658262461"
}
],
"count": 4
},
"comments": {
"count": 0
}
},
{
"id": "393459637370574_450229665031926",
"from": {
"category": "Consulting/business services",
"name": "Global Georgia",
"id": "393459637370574"
},
"story": "Global Georgia shared Embassy of Georgia in the Republic of South Africa's photo.",
"story_tags": {
"0": [
{
"id": "393459637370574",
"name": "Global Georgia",
"offset": 0,
"length": 14,
"type": "page"
}
],
"22": [
{
"id": "340928409306379",
"name": "Embassy of Georgia in the Republic of South Africa",
"offset": 22,
"length": 50,
"type": "page"
}
]
},
"picture": "http://photos-f.ak.fbcdn.net/hphotos-ak-snc7/385189_475566662509219_1872863393_s.jpg",
"link": "https://www.facebook.com/photo.php?fbid=475566662509219&set=a.405386502860569.99241.340928409306379&type=1",
"name": "Timeline Photos",
"caption": "Information on the meeting of the Ambassador of Georgia\r\nwith the National Librarian and Chief Executive Officer\r\nof the National Library of South Africa\r\n\r\nOn 24 January 2013 H.E. Mr Beka Dvali, Ambassador of Georgia held a meeting with Mr John Tsebe, the National Librarian and Chief Executive Officer of the National Library of the Republic of South Africa, and the Chair of the Conference of Directors of National Libraries (CDNL)).\r\nAmbassador of Georgia passed on Mr Tsebe several books to be catalogued as the first ever publications on Georgia at the National Library of South Africa.\r\nDuring the meeting, the parties discussed the possibilities of cooperation between the national libraries of the two countries, the issues of supplying Georgian and Georgia-related books, by the support of the Embassy, to the National Library of South Africa as well as the prospects of hosting by the library a literature event featuring contemporary Georgian author(s). \r\n\r\n24 January 2013\r\nPretoria",
"properties": [
{
"name": "By",
"text": "Embassy of Georgia in the Republic of South Africa",
"href": "https://www.facebook.com/EmbassyOfGeorgia?ref=stream"
}
],
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
"privacy": {
"value": ""
},
"type": "photo",
"status_type": "shared_story",
"object_id": "475566662509219",
"application": {
"name": "Photos",
"id": "2305272732"
},
"created_time": 1359387805,
"updated_time": 1359387805,
"comments": {
"count": 0
}
}
],
"paging": {
"previous": "https://graph.facebook.com/393459637370574/feed?limit=3&date_format=U&access_token=XXXX&since=1359555861&__previous=1",
"next": "https://graph.facebook.com/393459637370574/feed?limit=3&date_format=U&access_token=XXXX&until=1359387804"
}
}
How would I get this functionality working?
Any help/advice greatly appreciated
It looks like you'd have to spend a lot of time wrangling with infinite-scroll.js to get it to do what you want, because it depends on having pagination links in your HTML.
What would probably be easier would be to write your own Javascript to detect when the user is scrolling and automatically load stuff then, based on the next page link in your most recent JSON response.
If you look at the code for jscroll.js (a similar plugin to infinte-scroll, but with code that's a bit simpler) you'll probably a get a good idea of what to look for and when to load new content. Specifically, from line 84:
// Observe the scroll event for when to trigger the next load
function _observe() {
var $inner = $e.find('div.jscroll-inner').first(),
data = $e.data('jscroll'),
iContainerTop = parseInt($e.css('paddingTop')) + parseInt($e.css('borderTopWidth')),
iTopHeight = _isWindow ? _$scroll.scrollTop() : $e.offset().top,
innerTop = $inner.length ? $inner.offset().top : 0,
iTotalHeight = Math.ceil(iTopHeight - innerTop + _$scroll.height() + iContainerTop),
nextHref = $.trim(data.nextHref + ' ' + _options.contentSelector);
if (_checkNextHref(data) && !data.waiting && iTotalHeight + _options.padding >= $inner.outerHeight()) {
_debug('info', 'jScroll:', $inner.outerHeight() - iTotalHeight, 'from bottom. Loading next request...');
return _load();
}
}
Looking at the documentation, It seems to allow a functionality where it calls the link in the href via AJAX and returns the response to you.
If you make an initial call on pageload to populate your initial feed, then create a display: none link with something like:
#nextLink {
display: none;
}
and give it a href of the data['paging']['next'] then you could initialise the infinite scroll with something like:
$('.feedContainer').infinitescroll({
// other options
nextSelector: "a#nextLink",
dataType: 'json',
appendCallback: false
}, function(json, opts) {
// Update your next link to point to the next page
$('#nextLink').attr('href',json['data']['paging']['next']);
// Add your new feed rows here
var htmlStr = '<li>FeedContent</li>';
// Append it to the container
$('.feedContainer').append(htmlStr);
});
Use dataType 'jsonp' if it supports it.
That should roughly give you what you're looking for!

Categories