Message Boards Message Boards

Google Searches

Posted 9 years ago

In case anyone has had the chance to work with this before:

How to restrict my query to a specific data range?

e.g.

Import["https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=NASA", "JSON"]
POSTED BY: Sandu Ursu
15 Replies

I'm having trouble with this, despite getting an API browser type key from the Google Development platform, and a custom search ID. ServiceConnect["GoogleCustomSearch"] works as far as I can tell, returning a ServiceObject that is connected. But then when I do the following:

customsearch = ServiceConnect["GoogleCustomSearch"]

customsearch["Search", {"Query" -> "transactive memory", 
  "Site" -> "http://scholar.google.com", "MaxItems" -> 10}]

the second evaluation returns

ServiceObject[
 "GoogleCustomSearch", 
  "ID" -> "connection-03fd5d9f173245ebd05b0f1d96dde014"]["Search", \
{"Query" -> "transactive memory", 
  "Site" -> "http://scholar.google.com", "MaxItems" -> 10}]

No results are returned; my Mathematica 10.2 behaves as if I'm supplying the wrong arguments. The "ID" you see there is not the Custom Search ID I created through Google's Custom Search Engine page. I tried to put the ID in manually as an argument, and I get the same result (well, lack of result).

Any help would be appreciated.

POSTED BY: Abigail Nussey

Ideally once you have successful connection made to the service you should be able to make the request. Does the result of your second evaluation also gave some kind of message? Can you paste the output like below to see what it looks like?

In[1]:= customsearch = ServiceConnect["GoogleCustomSearch"]  
Out[1]= ServiceObject["GoogleCustomSearch",    "ID" -> "connection-48febb37b544c2662678576fb18ae2dc"]

In[5]:= customsearch["Search", {"Query" -> "transactive memory", 
"Site" -> "http://scholar.google.com", "MaxItems" -> 2}]

Out[5]= Dataset[{__Association}]

The id whcih you see in the result of your second evaluation is the connection id and has nothing to do with search engine id. This connection id is used by internal authentication mechanism.

POSTED BY: Damanjit Singh

Weird...It's working fine for me.

screenshot

Can you please share the output of:

SystemInformation["Small"]
PacletInformation["ServiceConnection_GoogleCustomSearch"]

Also, when using your Google credentials, do you get that box saying GoogleCustomSearch Connected? (Like the one in my screenshot after ServiceConnect)

. The "ID" you see there is not the Custom Search ID I created through Google's Custom Search Engine page. I tried to put the ID in manually as an argument, and I get the same result (well, lack of result).

The ID you see there is not the Google ID but the internal connection ID.

Posted 9 years ago

I have created a Google Custom search engine and from the site URL Basics tab can get the "Custom search engine ID" by clicking on its tab OK but cannot see how to get the "API key".

Help appreciated.

POSTED BY: Syd Geraghty

To get the API Key you first have to go to https://console.developers.google.com and create a project if you don't have one yet. Once you have the project (asuming you are using the new console interface), click the Credentials menu at the left. There you'll see all your credentials. If don't have one, click the Add credentials and, for GoogleCustomSearch, you need the API key Browser key type.

Posted 9 years ago

Thanks, but the manual doesn't really say how to get the credentials.

enter image description here

POSTED BY: Sandu Ursu

To get the API Key you first have to go to https://console.developers.google.com and create a project if you don't have one yet. Once you have the project (asuming you are using the new console interface), click the Credentials menu at the left. There you'll see all your credentials. If don't have one, click the Add credentials and, for GoogleCustomSearch, you need the API key Browser key type.

For the Custom search engine ID, you have to go to https://cse.google.com/all and add a search engine. Once you create it, just click on that and you'll get a screen with a lot of options. There's a button there that says Search engine ID. Click it and you'll get the ID you need.

Regarding your original question, GoogleCustomSearch API supports the dateRestrict parameter, however, the WL connection does not support that parameter yet (but we have plans to add more support to this service).

Please let me know if you have questions about this functionality.

Posted 9 years ago

Thank you, Christian!

To my knowledge, dateRestrict allows one to request results from a specified number of past days/weeks/months.. I would be more interested in results within a date rage (of course you can run 2 requests and then take the complement, but life is too short to do this).

Another point, if I make a query with my name, I get a dozen of results from plus.google.com, which don't appear if I search that in Google.

POSTED BY: Sandu Ursu

Yeah, I've also noticed that. My guess is that it's because, when you Google something directly from your browser, Google is using your personal preferences (specially if you are logged into your Google account) and user metadata. However, if you do it via the API, the custom search engine you created is what's controlling the search.

If you don't want those Google+ results to appear when using GoogleCustomSearch from the Wolfram Language, you can do:

gcs = ServiceConnect["GoogleCustomSearch"]
gcs["Search",{"Query"-> "Your name","Site"-> Except["plus.google.com"]}]

Feel free to ask anything if you still have issues with this or other services. Note that for web search, BingSeach is also available

Posted 9 years ago

10.3.0 for Microsoft Windows (64-bit) (October 9, 2015)

POSTED BY: Sandu Ursu

Did you get an Google Custom Search API key as per the manual:

https://reference.wolfram.com/language/ref/service/GoogleCustomSearch.html

POSTED BY: Sander Huisman

GoogleCustomSearch was released with Mathematica 10.2 so you should be good to use it.

Posted 9 years ago

It looks nice, but I cannot replicate the result.

POSTED BY: Sandu Ursu

You need at least version 10 to have ServiceExecute, I can't find when they introduced the GoogleCustomSearch, it might be 10.0 it might be 10.3. Which version of Mathematica are you using?

POSTED BY: Sander Huisman

BTW - have you seen THIS?

results = ServiceExecute["GoogleCustomSearch", "Search", 
{"Query" -> "Orion spacecraft", "FileType" -> Except["png"], "MaxItems" -> 5, "SearchType" -> "Image"}]; 
results[All, {1, 2, 6, 7}]

enter image description here

POSTED BY: Sam Carrettie
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract