在Result = Floor(TotalUnits(30) / FixedUnit(20)) * StaticValue(2);
谷歌工作之前,但现在当我尝试在我的网站上搜索某些内容时,请注意:
未经授权访问内部API。请参阅https://support.google.com/customsearch/answer/4542055
我认为问题在于有一个新的Api版本......
代码V1是这样的:
Custom Search Element V1
在此资源中,然后在正文中获取结果:
google.setOnLoadCallback(googlata);
google.load('search', '1');
function googlata(){
var customSearchControl = new google.search.CustomSearchControl('ID CSE');
customSearchControl.setResultSetSize(20);
customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
var options = new google.search.DrawOptions();
options.setAutoComplete(true);
options.enableSearchResultsOnly();
customSearchControl.draw('cse',options); // 'cse' is a div for serp results
customSearchControl.execute('keyword');
现在我怎样才能更改为V2?
可以使用此代码吗?
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<div id="cse"></div>
且只有
function gcseCallback() {
if (document.readyState != 'complete')
return google.setOnLoadCallback(gcseCallback, true);
google.search.cse.element.render({
div:'cse',
tag:'searchresults-only',
attributes:{
resultSetSize: 20,
noResultsString: "<div style='padding:10px'>Nothing</div>"
}
});
var element = google.search.cse.element.getElement('gsearch');
element.execute('keyword');
};
window.__gcse = {
parsetags: 'explicit',
callback: gcseCallback
};
(function() {
var cx = 'ID CSE';
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=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
我希望你能帮助我,对不起我的英语