Reddit Search API URL? - javascript

I'm trying to implement a search using reddit's api, but am not having much luck:
http://www.reddit.com/search.json?q=ferrari?jsonp=?
It's returning some json formatted text but no results.. If I search "cars", it returns 2 results, and the rest of my code won't recognize the objects. (Plus, I know there's more than 2 results for cars). Any idea on how to modify the URL?

Your URL looks wrong. I think you used a question mark instead of an amp to separate request variables.
I tried using http://www.reddit.com/search.json?q=ferrari and I got a lot of results in JSON format.
This will allow you to do the most basic search for reddit posts.
You can add other parameters, described on the reddit API page : http://www.reddit.com/dev/api#GET_search. You can also limit your search to one subreddit.
For example, to get the same results, sort by newest : http://www.reddit.com/search.json?q=ferrari&sort=new

It does work for me like so :
http://www.reddit.com/search.json?q=rest&jsonp=callback
and there is limit parameter which by default is 25 and the maximum is 100

Related

Handling search parameters URL PHP

I am wondering if I would be able to get some advice.
I am trying to build a search for my site and I want to link to be reusable so it can be sent as a link to someone else to see the same results.
The problem I have is that there is the possibility to have 100s of parameters for this search, so I dont think a GET requests in the URL are the right way to go.
I was thinking of the possibility of creating a JSON file that saves the parameters in the search and to give it a specific name say "qwer-eweq-qwe" then the URL link could be www.mysite.com/qwer-eweq-qwe
Then once a user would navigate to the URL it would then read the JSON file and pull the correct parameters.
Is there any other ways I could do this? Can seem to find too much online. any pointers would be very helpful
Thanks,
Richard
With so many parameters, please, consider switching way of dealing with it.
An idea would be to use a filter system. One POST method would create a filter with a set of parameters in body (either raw or JSON, does not matter).
POST /filter
The call would create (or not, if already exists) a filter.
The call would return a filter ID that you can use to search by fixed parameters:
GET /search/:filterid
That way, you even can manage cache limitations depending on filters, by invalidating those if needed.

First time using an API: How do I construct a request for the proper data from a quote API? Links included

I am using this API from Stands4 to get quotes. I was able to build my random quote generator for free code camp using their RANDOM tag in the request. Now I want to know how to write a request to get quote from a tv show for a personal project I am working on. Does anyone know how this is possible?
Here is the API doc: Link
In particular I am looking at the second and third lines of their Request parameters table. I want to use 'SEARCH' but don't know how to produce the correct 'query'. Maybe I am going about this wrong.
Here is the show I would like to get quotes from: Link
Here is what I tried. Goal is to get a random quote from the show.
http://www.stands4.com/services/v2/quotes.php?uid=MYUID&tokenid=MYTOKENID&searchtype=RANDOM&SEARCH&query=Its+Always+Sunny+In+Philadelphia
Unfortunately, these aren't the greatest docs so you'll have to play around with the "query=" part of your search. You're correct in thinking that's where to start.
Here's the approach I would take to make this work:
1. Searchtype=Search: I would start subbing in all sorts of different things from It's always Sunny and seeing what gets returned, including: character names, the show name, writer/actor names, and if all else fails show objects ("Paddy's pub" and "Day man") come to mind. Note: for things with spaces make sure you're using url-encoding.
2. Searchtype=Author: Take writer names and maybe character names to see if putting those in with an author search type returns anything.
3. Use their Scripts API: I'd hope something would come from that, but if it doesn't work, you can always try and find some scripts from their Scripts API and parse them.
If all else fails you can use a scraping tool like Import.io and grab quotes from a site like IMDB. Import.io is free and very easy to use.

Get fixed number of JSON objects from third-party API

I'm working with this returned API from a third party:
(note: returns LARGE dataset)
https://www.saferproducts.gov/RestWebServices/Recall?format=json
I know I can get this giant object like so:
$.getJSON('https://www.saferproducts.gov/RestWebServices/Recall?format=json', function(json, textStatus) {
console.log(json);
});
This returns ~7000 objects. There is no way in the API call to dictate how many objects you want returned. It's all or nothing.
Here's the question...can I use getJSON (or similar) to only get the first 5 objects and stop without having to load the entire JSON file first?
I did something similar a while a go. I used PHP to fetch a webpage of an api. Then I would cache it. Via PHP logic, I stored a variable inside a text file which contained all the information from the webpage. I had another file that stored the timestamp. Then, when the page was called, php would check the timestamp to see how old it was. If it was too old, it'd recache the page and return relevant information. If it was still valid, it would just return the cached information. If you only want the last 5, the PHP logic wouldn't be too hard to write that in. Then, jQuery would query the PHP page.
They don't have anything called out in their documentation for limiting the returns. I think their intent is for you to narrow down your search so you're not fetching every single item. You could always email them and ask as what Mike McCaughan said, if they don't have a 'limit' baked in, then no, it's not possible.
It also looks like they offer weekly downloads that you can just create your own API and add a limit property:
https://www.fda.gov/%20Safety/Recalls/EnforcementReports/default.htm
Reference:
https://github.com/presidential-innovation-fellows/recalls-api/wiki/data-sources
https://www.cpsc.gov/Recalls/CPSC-Recalls-Application-Program-Interface-API-Information/
https://www.cpsc.gov/Global/info/Recall/CPSC-Recalls-Retrieval-Web-Services-Programmers-Guide_3-25-2015.pdf
If there really is no option for limiting that call, then I'd suggest caching, showing some kind of processing wheel while the call takes place or narrowing your query. They have options to for filtering that may work for you such as the following:
RecallNumber
RecallDateStart
RecallDateEnd
LastPublishDateStart
LastPublishDateEnd
RecallURL
RecallTitle
ConsumerContact
RecallDescription
ProductName
ProductDescription
ProductModel
ProductType
RecallInconjunctionCountry
ImageURL
Injury
ManufacturerCountry
UPC – see caveat below
Hazard
Manufacturer
Remedy
Retailer

How to Exclude retweets and replies in a search api?

How to Exclude retweets and replies in a search api?
I am trying to fetch the feeds from twitter using search api, in the result I am getting replies and retweets also.
So I want to exclude replies and retweets.
How to do it anybody help me.
This is my url:
https://api.twitter.com/1.1/search/tweets.json?q=from:rioferdy5&count=20&result_type=recent
I beleive the above is incorrect, you can use filters in the search API but the documentation is very poor (non-existent?).
Your query would become:
?q=from:rioferdy AND -filter:retweets AND -filter:replies&count=20&result_type=recent
More tips for filtering were obtained here: How to Master Twitter Search: Basic Boolean Operators and Filters
Old post, but people might still stumble upon it.
Most query operators are documented here: https://dev.twitter.com/rest/public/search
But for the search/tweets method, you can also specify exclude:replies and/or exclude:retweets to filter out replies and retweets from the result.
Just test it in the API Console Tool and see for yourself.
Bonus: Another undocumented query operator is filter:verified to get tweets from verified users.
Example query: cats filter:vine filter:verified exclude:replies exclude:retweets
In the new Search Tweets API, including the following parameters will remove different flavors of retweets:
-is:retweet Excludes retweets
-is:quote Excludes quote tweets
-is:reply Excludes replies
Please see the API documentation here: Search Tweets - Build a Query
Only Mike Chen's response (which oddly had 0 upvotes until I upvoted it) is correct. The rest of the answers here are out of date due to the launch of the Twitter API v2. I would comment directly on Mike's answer, but I don't have enough reputation.
Very late reply, like everyone else but I feel the second answer here by Paul should be the "correct" one. I wish twitter would document this better, or make it more well known but there are a TON of search filters you can do, even with their standard API in 2018.
https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators
Here's a rather comphrensive list of examples :) and retweets is somewhere in the middle.
-filter:retweets
yes, you can exclude the retweets during search API by adding -RT in the search string (q). Ex: search?q="#demo -RT"
This is allowed as documented in the official documentation
puppy -filter:retweets containing “puppy”, filtering out retweets
https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators.html
Found this while searching how to do this in the new v2 API, and it's now puppy -is:retweet -is:reply (no longer need the ANDs either)
https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query#list
According to the official documentation
Pass the following parameter exclude_replies=true
Sorry I'm late to the party here. I agree with Hitesh in that they do not provide a way to exclude retweets natively, but every tweet that is a retweet has a retweet object in the json returned. So you could loop through your tweets and exclude any that have a retweeted_status typeof 'object' (meaning they are a retweet from someone else) or keep those that have a typeof 'undefined' (meaning they are original). The issue with retweet_count=0 is that someone like #pattonoswalt will have retweets on all of his tweets. So the count will never be zero even though they are all originals.
You could use something like so in a loop:
if(typeof tweets[i].retweeted_status === 'object') {tweets.splice(i,1);}
or
if(typeof tweets[i].retweeted_status !== 'undefined') {tweets.splice(i,1);}
There is no direct way to exclude retweets and replies from the api. However, you can filter out the results you have got.
For replies, you can check if the in_reply_to_status_id field you get from api is null, that means its not a reply else if it contains a id, then its a reply.
For retweet, if you want posts that have not been retweeted ever, you can check for retweet_count = 0 or if you want posts that have not been retweeted by your authenticated user, you can check for retweeted = false
Just use nitter.net
it allows you to exclude things from the search results (via advanced search options on the right end of its search bar), and it even provides its own RSS feed. On top it expands these t.co short URLs and replaces the youtube URL with the invidio.us URL
In the end you may use your RSS feed as a trigger for other web-applets through the self-hostable interface called Huginn

How to get Wikipedia article data from Freebase suggest response

I'm looking for a simple way to get data about a university (name, native_name, city etc) from the Wikipedia infobox after a user selects a university from Freebase suggest. The dataset returned from freebase, however, is very small and doesn't include the wikipedia link unfortunately.
Currently I am using the "name" property and making an ajax request to http://live.dbpedia.org/data/"+name+".json. This often works but while doing some tests it turned out the name doesn't always map directly to the correct page. Let me split my question in a few to make myself clear:
Is it possible to configure the Freebase suggest plugin so that the
response includes the wikipedia link?
OR is there a similar plugin that queries DBpedia directly and is as
simple and user-friendly as Freebase's?
OR, as a plan B, is there a way to send a request to
"live.dbpedia.org" so that it only returns me the json after
redirects? On the Wikipedia API I can send a "redirects" variable that does this. But then I'd have to parse the data myself…
The problem with the plan B is that nothing guarantees that the freebase object's name will ever lead me to the correct Wikipedia page. Even after the redirects…
I swear I've read a lot of API documentation but everything is extremely confusing and I chose not to read long tutorials about RDF, SPARQL and MQL because I really don't think the solution should be so complicated. I'm asking here because I really hope I'm missing a simple solution…
UPDATE
{
id: "/en/babes-bolyai_university",
lang: "en",
mid: "/m/08c4bf",
name: "Babeş-Bolyai University",
notable: {
id: "/education/university",
name: "College/University"
},
score: 37.733559
}
This is the result I get after selecting "Babeş-Bolyai University" in the suggest widget.
SOLUTION
I assumed I can't configure the Suggest widget to return more data, so after getting the Freebase ID of the object I just send another request, this time with a query specifically asking for the Wikipedia ID. I didn't know any MQL and couldn't find the name of the Freebase field with the Wikipedia ID. Maybe I'm stupid but the Freebase documentation really confuses me. In any case Tom Morris' answer and this question helped me build the query that returned what I wanted:
https://www.googleapis.com/freebase/v1/mqlread?query={"id":"/en/babes-bolyai_university","key":{"namespace":"/wikipedia/en_title","value":null}}
The strings in the result come with numeric codes for special unicode characters though (in my case Babe$0219-Bolyai_University). I've been able to convert the code with String.fromCharCode(parseInt(219, 16)) but if someone knows of a way to convert the whole string that would be helpful. Otherwise I can just make my own function replacing the "$dddd" pattern with the corresponding character.
Thanks for the help!
There isn't a DBpedia autosuggest comparable to Freebase Suggest as far as I'm aware.
Anything that's in Freebase can be retrieved with Suggest by using an MQL expressions in the output parameter. For simple things, e.g. names, aliases, the MQL is basically just a JSON snippet containing the relevant property name.
EDIT: The output parameter doesn't actually appear to be documented in the context of Suggest, but anything that isn't a Suggest parameter gets passed through transparently to the Freebase Search API, so you can use all of the stuff described here: https://developers.google.com/freebase/v1/search-output You can get as much or as little information as you require returned with each suggestion.
If you do need to query DBpedia, you should be using the Wikipedia/DBpedia key, which is not necessarily the same as the name. For English Wikipedia, the key is in the namespace /wikipedia/en or if you want the numeric Wikipedia ID in the namespace `/wikipedia/en_id'. Replace the 'en' with the appropriate language code if you want to query other language Wikipedias. These keys have some non-ASCII characters escaped, so if you need to unescape them, you can use the documentation here: http://wiki.freebase.com/wiki/MQL_key_escaping
You can update the "flyout_service_path" parameter. Here there is a description in the freebase suggest documentation (https://developers.google.com/freebase/v1/suggest). I'm using this configuration for to get all the keys of a entity.
$(inputClass).suggest(
{
"key" : _FREEBASE_API_KEY_BROWSER_APP,
"flyout_service_path":"/search?filter=(all mid:${id})&output=(notable:/client/summary description type /type/object/key)&key=${key}"
}
).bind("fb-select", this.fbSelectedHandler);
In the freebase response I can see now in the "output" parameter the "/type/object/key" with all the keys of the entity (wikipedia,etc..).
My question now is how I can acquire this data from output ?. In the "fb-select" event the "data" variable, don't carry this fields.
Some help, please..

Categories