Does Bing has an option similar to Google Custom Search or Yahoo where I can use Bing to power the search results on my site?
Couple requirements:
Works with an ASP.NET site (is a .NET project)
Host the search box and results on my own website
Ability to customize the look and feel of the results to match my site (Full control is ideal but I understand it's not possible with free solutions)
I did a search for Bing custom search and found this: http://www.bing.com/siteowner/ but it's not exactly what I am looking for.
The query string Bing uses is:
http://www.bing.com/search?q=&src=IE-SearchBox&FORM=IE8SRC
(this is the template URL from the Bing search provider in IE). All you have to do is insert your search terms after the q parameter. A good way to test this is to actually execute a search and see the url in the address box of the browser:
http://www.bing.com/search?q=how+to+query+bing&src=IE-SearchBox&FORM=IE8SRC
you can drop the src and FORM parameters, Bing will just be using those for statistical purposes.
To get the results to appear in your own page, use an iframe, give it an id, and sets its src url (using javascript) to the search url you have constructed.
var frame = document.getElementById('mySearchFrame');
if (frame != null)
frame.src = 'http://www.bing.com/search?q=' + mySearchTerms;
Note that if you want to style the page then you will have to query Bing from code behind and "scrape" the results and place them into your own page. (Or you could just send the page back but modify the contents of it before doing so, but to do this will be violating Bing's terms of use - MS supply Bing for you to use for free, but it is on their terms, which means you will not be able to delete any advertising or change the look and feel of the page - there are no free rides in this world :).
You can sign up for site search and query Bing via jsonp and display results via javascript (exact code untested)
function searchDone(results) {
if(results.SearchResponse.Web.Results && results.SearchResponse.Web.Results.length > 0) {
for (var i = 0; i < results.SearchResponse.Web.Results.length; i++) {
result = results.SearchResponse.Web.Results[i];
item = document.createElement('li');
item.innerHTML = '' + AntiXssLibrary.HtmlEncode(result.Title.replace(/\uE000/g, "").replace(/\uE001/g, "")) + '' + '<blockquote>' + AntiXssLibrary.HtmlEncode(result.Description.replace(/\uE000/g, "").replace(/\uE001/g, "")) + '</blockquote>';
// append child to document somewhere
}
}
}
var serviceURI = "http://api.search.live.net/json.aspx?JsonType=callback&JsonCallback=searchDone&sources=web&Options=EnableHighlighting";
var appid = "&Appid=YOUR_BING_APP_ID";
var query = "&query=site:http://YOURDOMAIN.com/ <%=Request.Querystring["query"] %>";
var fullUri = serviceURI + appid + query;
var head = document.getElementsByTagName('head');
var script = document.createElement('script');
script.type = "text/javascript";
script.src = fullUri;
head[0].appendChild(script);
Related
I am using the Google C# API for the Custom Search and have it working and returning results, however I cannot see a way to make the paging work correctly.
Looking at what I get returned, no where does it tell me how many pages there are in the result? It just has a .Start property? Which is not much good unless I know how many 'pages' of results I have?
Am I missing something stupid here? Here is an example of the code I have so far
var svc = new CustomsearchService(new BaseClientService.Initializer { ApiKey = settings.GoogleCustomSearchApi });
var listRequest = svc.Cse.List(searchTerm);
listRequest.Cx = settings.GoogleCustomSearchEngineId;
listRequest.ImgSize = CseResource.ListRequest.ImgSizeEnum.Medium;
listRequest.Num = 10;
// List to hold everything in
var resultItems = new List<Google.Apis.Customsearch.v1.Data.Result>();
// Result set 1
listRequest.Start = 1;
var search = listRequest.Execute();
resultItems.AddRange(search.Items);
I have resulted at the moment to doing two or three calls one after the other and getting a load of results back. But I would prefer to have this properly paged.
The JSON API response has totlResults field:
https://developers.google.com/custom-search/json-api/v1/reference/cse/list#response.
It should be exposed under search.Queries
Found it, its in
search.SearchInformation.TotalResults
Good day all.
Does anyone has a working example how to make Google Plus post through .NET (C#).
I have already tried google and stackoverflow search, but did not manage to find the solution.
I successfully get posts:
public void Post(string text)
{
PlusService plus = new PlusService {Key = "MYVERYSECRETKEY"};
ActivitiesResource ar = new ActivitiesResource(plus, null);
ActivitiesResource.ListRequest list = ar.List("108055870103885325249", new ActivitiesResource.Collection());
ActivityFeed feed = list.Fetch();
string activityKey = "";
foreach (var a in feed.Items)
if (a.Url == "https://plus.google.com/108055870103885325249/posts/EtvvUgn8eKz")
{
activityKey = a.Id;
break;
}
ActivitiesResource.GetRequest get = ar.Get(activityKey);
Activity act = get.Fetch();
var sb = new System.Text.StringBuilder();
sb.AppendLine("Title: " + act.Title);
sb.AppendLine("URL:" + act.Url);
sb.AppendLine("Published:" + act.Published);
sb.AppendLine("By:" + act.Actor.DisplayName);
sb.AppendLine("Annotation:" + act.Annotation);
sb.AppendLine("Content:" + act.Object.Content);
sb.AppendLine("Type:" + act.Object.ObjectType);
sb.AppendLine("# of +1s:" + act.Object.Plusoners.TotalItems);
sb.AppendLine("# of reshares:" + act.Object.Resharers.TotalItems);
}
But I cannot find any method for making posts.
Thanks in advance.
Currently, the Google+ API does not allow writing of posts to a user's activity stream. You can use the moments.insert method in the Google+ REST API to write App Activities to the user's profile, which the user can choose whether to share publicly or to their circles.
You would work with the REST API in a similar manner to other REST APIs in .NET by POSTing to the moments.insert end-point.
This feature is now available to apps that request the https://www.googleapis.com/auth/plus.login scope and specify the type of moments that the app wants to write in the request_visible_actions parameter either in the Google+ Sign-In button or directly in the OAuth query parameters.
I have no experience with webbrowser control I'm trying to do the following:
Navigate to website and to scrape the cookie values it gives back (specific with regex). I tried to search for this here & google there is no information about this, Are the webbrowser control connected to IE? This will be impossible to read the values right? Any way to capture the cookies? Like CookieContainer?
I have one code i use with httpwebrequest it can be an example to what I'm trying to do with webbrowser control:
List<string> cookieValues = new List<string>();
foreach (Cookie cookie in agent.LastResponse.Cookies)
{
cookieValues.Add(cookie.Value);
}
foreach (string i in cookieValues)
{
Match match2 = Regex.Match(i, #"bert=([\w]*)",
RegexOptions.IgnoreCase);
// Ensure match
if (match2.Success)
{
// Finally, we get Group value and display it.
key2 = match2.Groups[1].Value;
}
Thanks for the help like always!
I am querying a Picasa gallery and when I dig into the entries that are returned, I can't find the full size image. I can only see a much smaller, re-sized image (data[0].Content.AbsoluteUri). I know Google retains the full size image because I can see it when I view my Picasa gallery online. Where is the full size image?
var picasaService = new PicasaService("Gallery");
var photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri("GOOGLEUSERNAME", "GALLERYID"));
var photoFeed = picasaService.Query(photoQuery);
var data = photoFeed.Entries;
Hidden in the documentation it is possible to specify the size of the images in the feed. This is using the "imgmax" parameter:
https://developers.google.com/picasa-web/docs/2.0/reference#Parameters
Which can have a value set to "d" to request full sized images
This is not supported directly in the c# API, but you can achieve the desired result using the "extraParameters" field on the PhotoQuery object.
Your code then becomes:
var picasaService = new PicasaService("Gallery");
var photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri("GOOGLEUSERNAME", "GALLERYID"));
// add the extra parameter to request full size images
photoQuery.ExtraParameters = "imgmax=d";
var photoFeed = picasaService.Query(photoQuery);
var data = photoFeed.Entries;
short answer:
media:group/media:content[#url] path in a query to get the gdata photo ENTRY from the picasa GData service contains the link you want.
Longer answer:
interactively query the Gdata api for picasa using oauth playground\
https://code.google.com/oauthplayground and select picasa from the list and get
authorize button ... then allow access button and you can query the api using the form
make a query for the ENTRY URI of desired photo (your ...user/.. /albumid .. /photoid )
inspect the content of media:group/media:content[#url] sample below
The URI to the big photo is valueOf the url attribute in the above expression
sample value for one of my picasa photos
url=https://lh3.googleusercontent.com/-_FFMNGPU1TQ/TtukXyN4eCI/AAAAAAAACso/EzPmut2iKVQ/DSC01612.JPG
Using the oauth 2.0 playground for a query to get the entry of one of my photos...
Request:
GET /data/entry/api/user/rowntreerob/albumid/5682316071017984417/photoid/5682316083381958690?alt=json
Note: filter response using http://json.parser.online.fr/
Response:
"media$group":{
"media$content":[
{
"url":"https://lh3.googleusercontent.com/-_FFMNGPU1TQ/TtukXyN4eCI/AAAAAAAACso/EzPmut2iKVQ/DSC01612.JPG",
"height":512,
"width":341,
"type":"image/jpeg",
"medium":"image"
}
The link to the large photo that you want is in the url attribute above...
Using the "fields=" tag, you can directly get the link as in below req/ resp from gdata...
GET /data/entry/api/user/rowntreerob/albumid/5682316071017984417/photoid/5682316083381958690?alt=json&fields=media%3Agroup%2Fmedia%3Acontent%5B%40url%5D
{
"version":"1.0",
"encoding":"UTF-8",
"entry":{
"xmlns":"http://www.w3.org/2005/Atom",
"xmlns$media":"http://search.yahoo.com/mrss/",
"media$group":{
"media$content":[
{
"url":"https://lh3.googleusercontent.com/-_FFMNGPU1TQ/TtukXyN4eCI/AAAAAAAACso/EzPmut2iKVQ/DSC01612.JPG",
"height":512,
"width":341,
"type":"image/jpeg",
"medium":"image"
}
]
}
}
}
I have a search page on my .NET 3.5 Web Forms site that redirects a user to an external site based on the user's search parameters. I would redirect to: http://www.site.com/search.aspx?searchterm=Hello.
But now they are changing the site so that the search parameter is passed as a POST parameter, and not in the query string. So the page is expecting "searchterm".
So not only do I need to redirect to the external page, I have to post data to the page as well. I have no idea how to do this and I don't know where to start.
Is this something I can do in Web Forms without some glitchy workaround? Or maybe it can be done using jQuery?
Most browsers will explicitely deny this. Doing a cross server post like this would lead to security issues.
You can create simple JavaScript function for execute POST redirect to external page (dynamicaly generate and initilaze form object and submit it).
For example (values pattern: a=1&b=2&c=3 ...):
function bind(pageURL, values) {
var form=document.createElement('form');
form.action= pageURL;
form.target='_blank';
form.style.display = 'none';
form.method = 'POST';
var valuesSplit = node.get_value().toString().split("&");
for (var i = 0; i < valuesSplit.length - 1; i++) {
var p = valuesSplit[i];
var ps = p.split('=');
addParam(form, ps[0], ps[1]);
}
document.body.appendChild(form);
form.submit();
}
function addParam(form,key,value){
var input= document.createElement('input');
input.name=key;
input.value=value;
form.appendChild(input);
}