Google Custom Search returning too many pages - google-custom-search

In our site we have a custom google search. When you do a search all ten paginated pages come back, however the last three or four will be empty and just display "No Results"
from what I've been reading, this shouldn't happen. If there are no results on the page then it should redirect you to the last page that does have content. Is there an attribute to make sure this happens?
the code looks something like this
(function() {
var id= '#id#'; // Insert your own Custom Search engine ID here
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + id;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
and then
<gcse:searchresults-only ></gcse:searchresults-only>

Have you tried using the resultSetSize attribute to limit the result set? This should limit to a maximum of 10 pages with 10 results per page. If there are fewer results, you shouldn't get 10 records. I believe the default here is 10 in place of filtered_cse.
<gcse:searchresults-only resultSetSize="filtered_cse"></gcse:searchresults-only>

Related

Optimisation of google api requests to retrieve data from youtube videos

I'm trying to build a website with a section that displays the last video of a youtube channel and the thumbnails and titles of the next 9 most recent videos. The problem I'm having is that I consume the quota of requests just by testing the website.
To get this information I use Google's API. I retrieve the last 10 videos of the channel as follows:
<?PHP
include('global_variables.php');
$randomNumber = rand(2,10);
$randomKey = "api.key$randomNumber";
$data = file_get_contents("https://www.googleapis.com/youtube/v3/search?key=".$GLOBALS['api_key']."&part=snippet&channelId=".$GLOBALS['channel_id']."&order=date&maxResults=".$GLOBALS['videos_in_playlist']);
$json = json_decode($data);
echo $data;
?>
I call this PHP file in these ways:
// TO LOAD PLAYING YOUTUBE VIDEO
function loadVideo(iframe) {
$.getJSON("load_playing_video.php",
function(data) {
var videoNumber = (iframe.getAttribute('vnum') ? Number(iframe.getAttribute('vnum')) : 0);
iframe.setAttribute("src", "https://youtube.com/embed/" + data.items[videoNumber].id.videoId+ "?controls=1&autoplay=1&color=white");
// PLACE VIDEO TITLE
$("#playing-video-title").html(data.items[videoNumber].snippet.title);
// PLACE VIDEO DESCRIPTION
$("#playing-video-description").html(data.items[videoNumber].snippet.description);
}
);
}
loadVideo(document.querySelector("#playing-video"));
// TO LOAD THUMBNAILS AND TITLES ON SIDEBAR
$.getJSON("load_playing_video.php",
function(data) {
for (var index = 0; index < <?php echo $GLOBALS['videos_in_playlist']?>; index++) {
var videoImage = data.items[index].snippet.thumbnails.default.url;
var title = data.items[index].snippet.title;
var imgId = "#playlist-thumbnail" + index;
var titleId = "#playlist-title" + index;
document.querySelector(imgId).setAttribute("src",videoImage);
document.querySelector(titleId).innerHTML = title;
}
}
);
I was hoping someone could help me optimise the number of requests I do.
And if someone knows how I could increase the quota of requests (even if I have to pay) I would really appreciate some guidelines.
Thank you!!

Crunchbase Data API v3.1 to Google Sheets

I'm trying to pull data from the Crunchbase Open Data Map to a Google Spreadsheet. I'm following Ben Collins's script but it no longer works since the upgrade from v3 to v3.1. Anyone had any luck modifying the script for success?
var USER_KEY = 'insert your API key in here';
// function to retrive organizations data
function getCrunchbaseOrgs() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Organizations');
var query = sheet.getRange(3,2).getValue();
// URL and params for the Crunchbase API
var url = 'https://api.crunchbase.com/v/3/odm-organizations?query=' + encodeURI(query) + '&user_key=' + USER_KEY;
var json = getCrunchbaseData(url,query);
if (json[0] === "Error:") {
// deal with error with fetch operation
sheet.getRange(5,1,sheet.getLastRow(),2).clearContent();
sheet.getRange(6,1,1,2).setValues([json]);
}
else {
if (json[0] !== 200) {
// deal with error from api
sheet.getRange(5,1,sheet.getLastRow(),2).clearContent();
sheet.getRange(6,1,1,2).setValues([["Error, server returned code:",json[0]]]);
}
else {
// correct data comes back, filter down to match the name of the entity
var data = json[1].data.items.filter(function(item) {
return item.properties.name == query;
})[0].properties;
// parse into array for Google Sheet
var outputData = [
["Name",data.name],
["Homepage",data.homepage_url],
["Type",data.primary_role],
["Short description",data.short_description],
["Country",data.country_code],
["Region",data.region_name],
["City name",data.city_name],
["Blog url",data.blog_url],
["Facebook",data.facebook_url],
["Linkedin",data.linkedin_url],
["Twitter",data.twitter_url],
["Crunchbase URL","https://www.crunchbase.com/" + data.web_path]
];
// clear any old data
sheet.getRange(5,1,sheet.getLastRow(),2).clearContent();
// insert new data
sheet.getRange(6,1,12,2).setValues(outputData);
// add image with formula and format that row
sheet.getRange(5,2).setFormula('=image("' + data.profile_image_url + '",4,50,50)').setHorizontalAlignment("center");
sheet.setRowHeight(5,60);
}
}
}
This code no longer pulls data as expected.
I couldn't confirm about the error messages when you ran the script. So I would like to show about the clear difference point. It seems that the endpoint was changed from https://api.crunchbase.com/v/3/ to https://api.crunchbase.com/v3.1/. So how about this modification?
From :
var url = 'https://api.crunchbase.com/v/3/odm-organizations?query=' + encodeURI(query) + '&user_key=' + USER_KEY;
To :
var url = 'https://api.crunchbase.com/v3.1/odm-organizations?query=' + encodeURI(query) + '&user_key=' + USER_KEY;
Note :
From your script, I couldn't also find query. So if the script doesn't work even when you modified the endpoint, please confirm about it. You can see the detail of API v3 Compared to API v3.1 is here.
References :
API v3 Compared to API v3.1
Using the API
If this was not useful for you, I'm sorry.

Fetch users liked Instagram-images after API update 2016

Hey!
After Instagram updated its API on the 1. june 2016 we are not able to get out JavaScript Instagram implementation to work. We inspected the client-setup and noticed that it has been put in Sandbox mode. When trying to resubmit then none of the valid user cases did fit, and we understood that they had removed our rights to fetch other peoples content through the account without getting permission from each individual owner.
As far as i understood, the new parameter "scope" needs to be set to "public_content" and this requires the users permission.
So at the moment the solution below only fetches the users own pictures that is self-liked. Before we also got other peoples images that the user had liked.
So, do anyone know how to fetch liked content of an account post 1. june 2016?
Does getting a Instagram Business account help you for displaying other peoples content?
Here is the code example with an additional filter on the hashtags.
If anyone got a better idea of how to filter on hashtags and liked content at the same time please let me know :)
$.fn.instagramFeedInit = function()
{
if(!$('#instagram-content').length)
{
return;
}
var container = $('#instagram-content');
var tag = container.data('hashtag');
var image_display_count = container.data('image-count');
var access_token = [INSERT_TOKEN_OR_SOUTH_PARK_REFERENCE_HERE];
$.ajax({
type:'GET',
url: 'https://api.instagram.com/v1/users/self/media/liked?access_token=' + access_token + '&callback=callback&count=99999',
jsonp: 'callback',
dataType: 'jsonp',
success: function(response) {
var container = $('#instagram-content');
var i = 0;
// Loops through images
$(response.data).each(function(i, el){
// Check that it has correct tag
if(jQuery.inArray(tag, el.tags) !== -1)
{
var imageTitle = el.caption.text;
var image = el.images.low_resolution.url;
var refImage = el.images.standard_resolution.url;
if (el.type === 'video') {
var videoLink = el.videos.standard_resolution.url;
container.append('<a class="lightbox instagramimage mfp-iframe" title="' + imageTitle + '" href="' + videoLink + '" ><img src="' + image + '"></a>');
}
else {
container.append('<a class="lightbox instagramimage" title="' + imageTitle + '" href="' + refImage + '" ><img src="' + image + '" class="img-responsive"></a>');
}
i++;
// If we have reached maximum display images
if(i == image_display_count) return false;
}
});
}
});
};
Be aware that if you are in Sandbox mode, only post from authorized Sandboxed users will appear in any api requests. Regardless of whether you have the public_access scope.
Note: you need to add scope=public_access to your authorization URL now. It's no longer included by default
E.g A and B are both sandbox users C is not.
A likes a post from C.
The liked media endpoint for A will not include the post from C. He is invisible to your sandbox app
A then goes an likes a post from B
The liked media endpoint for A will now include the post from B as he is visible to your sandbox app

Fiddler: Programmatically add word to Query string

Please be kind, I'm new to Fiddler
My purpose:I want to use Fiddler as a Google search filter
Summary:
I'm tired of manually adding "dog" every time I use Google.I do not want the "dog" appearing in my search results.
For example:
//www.google.com/search?q=cat+-dog
//www.google.com/search?q=baseball+-dog
CODE:
dog replaced with -torrent-watch-download
// ==UserScript==
// #name Tamper with Google Results
// #namespace http://superuser.com/users/145045/krowe
// #version 0.1
// #description This just modifies google results to exclude certain things.
// #match http://*.google.com
// #match https://*.google.com
// #copyright 2014+, KRowe
// ==/UserScript==
function GM_main () {
window.onload = function () {
var targ = window.location;
if(targ && targ.href && targ.href.match('https?:\/\/www.google.com/.+#q=.+') && targ.href.search("/+-torrent/+-watch/+-download")==-1) {
targ.href = targ.href +"+-torrent+-watch+-download";
}
};
}
//-- This is a standard-ish utility function:
function addJS_Node(text, s_URL, funcToRun, runOnLoad) {
var D=document, scriptNode = D.createElement('script');
if(runOnLoad) scriptNode.addEventListener("load", runOnLoad, false);
scriptNode.type = "text/javascript";
if(text) scriptNode.textContent = text;
if(s_URL) scriptNode.src = s_URL;
if(funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName('head')[0] || D.body || D.documentElement;
targ.appendChild(scriptNode);
}
addJS_Node (null, null, GM_main);
At first I was going to go with Tampermonkey userscripts,Because I did not know about Fiddler
==================================================================================
Now,lets focus on Fiddler
Before Request:
I want Fiddler to add text at the end of Google Query string.
Someone suggested me to use
static function OnBeforeRequest(oSession: Session) {
if (oSession.uriContains("targetString")) {
var sText = "Enter a string to append to a URL";
oSession.fullUrl = oSession.fullUrl + sText;
}
}
Before Response:
This is where my problem lies
I totally love the HTML response,Now I just want to scrape/hide the word in the search box without changing the search results.How can it be done? Any Ideas?
http://i.stack.imgur.com/4mUSt.jpg
Can you guys please take the above information and fix the problem for me
Thank you
Basing on goal definition above, I believe you can achieve better results with your own free Google custom search engine service. In particular, because you have control over GCSE fine-tuning results, returned by regular Google search.
Links:
https://www.google.com/cse/all
https://developers.google.com/custom-search/docs/structured_search

How to use Twitter Api To Get more than 20 list Members in a single request?

i want to get more than 20 users using the the twitter api in a single request
is there any parameter that specifies it?
i am using this api
http://api.twitter.com/1/Barelyme/Politics/members.xml?cursor=-1
According to the Twitter List API Docs:
http://apiwiki.twitter.com/Twitter-REST-API-Method:-GET-list-members
You cant get more than 20 in a single request.
If you're using twitteroauth by abraham, you can iterate through the pages of list members (this example assumes $connection is already defined by a functional implementation of twitteroauth):
$user = $connection->get('account/verify_credentials'); //Gets/Tests credentials
$listmembers = $connection->get("{$user->screen_name}/LISTNAMEORID/members"); //Gets first page of list members; MUST edit "LISTNAMEORID"
$pagevalue = ""; //Set page value for later use
if($listmembers->next_cursor == 0){ //There is only one page of followers
for ($j=0, $k=count($listmembers->users); $j<$k; $j++){
//Your actions here
//print_r($listmembers); //Displays the page of list members
}
} else { //There are multiple pages of followers
while ($pagevalue!=$listmembers->next_cursor){
for ($j=0, $k=count($listmembers->users); $j<$k; $j++){
//Your actions here
//print_r($listmembers); //Displays the page of list members
}
$pagevalue = $listmembers->next_cursor; //Increment the 'Next Page' link
$listmembers = $connection->get("{$user->screen_name}/LISTNAMEORID/members", array('cursor' => $pagevalue)); //Gets next page of list members; MUST edit "LISTNAMEORID"
}
}
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$listmembers = $connection->get("MexicoTimes/mexicanpoliticians/members");
$members = array();
while ($listmembers->next_cursor_str != "0") {
foreach($listmembers->users as $user)
$members[] = $user;
$cursor = $listmembers->next_cursor_str;
$listmembers = $connection->get("MexicoTimes/mexicanpoliticians/members", array('cursor' => $cursor));
}
This one worked for me with Abraham's Twitteroauth
Probably not though, you can poll multiple times > 1 for more data.
Given that twitter said you can't do it, you Probably can't