How to specify a language using Insight API for Twitter from IBM Bluemix Platform - twitter

I'm starting to use Insight API for Twitter from IBM Bluemix.
It's hard to find supporting resource for using this. So far I am using CURL and specifically formed URL to query the API service, and the service returns results in JSON format.
Here's an example of the URL I used with CURL to search for some tweets with the API:
https://(my seucrity key)#cdeservice.mybluemix.net:443/api/v1/messages/search?q=$MSFT%28posted:2016-01-01T00:00:00Z,2016-09-01T00:00:00Z%29&size=20
This URL returns a JSON object with tweets with keyword #MSFT, and between the time frame of 2016-1-1 to 2016-9-1, only return 20 tweets.
I would like to add to that link by specifying a language for the tweet to search for, so far I come up empty. Can you please help me ?
I have tried adding the following to the URL and did not do anything:
lang=EN, lang="en"
lang:en, lang:EN
Thanks.

The syntax is lang:en and you need to make sure to include it as part of your query.
I created the following query based on the one you provided in your question:
https://username:password#cdeservice.mybluemix.net:443/api/v1/messages/search?q=(%24MSFT%20AND%20posted%3A2016-01-01T00%3A00%3A00Z%2C2016-09-01T00%3A00%3A00Z%20AND%20lang%3Aen)&size=20
The unencoded query is
($MSFT AND posted:2016-01-01T00:00:00Z,2016-09-01T00:00:00Z AND lang:en)
You can find documentation here.
But in this link you can find more details on the syntax, which is:
/api/v1/messages/search?q=QUERY&size=NUMBER&from=NUMBER

Related

Can I achieve AND instead of OR in Swagger API generated by JHipster?

I set up a basic JHipster project and generated an entity that supports filtering with JDL.
The generator made a Swagger API which I use for querying the database.
The Swagger API doc shows me a list of parameters which can be used to build query.
The template query looks like this:
GET /api/client?name.equals=john&surname.equals=doe&country.in=uk&country.in=de
The request works fine but the parameters are chained like name==john OR surname==doe OR country==uk OR country==de so I get all johns, does, and everoyne from uk and de.
This is ok, but for some queries i need name==john AND surname==doe so not all Johns and Does but specifically John Doe. I searched here and on the swagger forum but couldn't find the answer.
My question is: how do I achieve changing the OR to AND in the query?
Does this swagger query support AND or do I have to make changes in the backend?
Your question is not about swagger, this is why you could not find anything in swagger forum.
It's about JHipster JPA entity filtering and the answer is no: you can't generate code that would use a OR.
You must code it yourself, look at the *QueryService classes and assemble your criteria with the logic you need.

Using Python RegEx in Zapier Formatter Extract Pattern

I have a field in an RSS item that includes a URL such as:
https://www.facebook.com/9999249845065110
https://www.yelp.com/biz/bix-berkeley-2?hrid=TaFUhHhVrhEJdCPjaB6RUQ
https://www.google.com/search?q=hello%20Signs%20&%20Graphics&ludocid=1720220414695611454#lrd=0x0:0x17df735a614e9c3e,1
I'm trying to setup a Zap in Zapier using the Formatter tool to essentially extract the root domain without the .com. So:
facebook
yelp
google
I have no clue how to use the Formatter Extract Pattern tool though. Can't figure out the syntax.
Best case scenario, it can look at any URL and extract the name of the site (e.g. facebook/google/yelp). If that's too complicated, then I could provide a finite list of what terms to look for and have it return the first (and only) one found. So it would check if the URL contained facebook or google or yelp and if so return that name as a value.
Any help would be appreciated. Thanks.
David here, from the Zapier Platform team.
This is totally possible. The input is the text you want to search (the full url) and the pattern is your regular expression.
In your case, you want to find the word between www. and .com. Use the regular expression www\.(\w+)\.com.
That worked for me, and pulled out yelp.
You can see each part of the regex explained here: https://regex101.com/r/KmwMAV/1
​Let me know if you've got any other questions!

Search multiple keywords in Youtube GData Youtube class

The Youtube API document says that multiple keywords can be searched during video fetch as per the below link.
https://developers.google.com/youtube/2.0/reference#Searching_for_videos
The below link gives some examples for the same. The example provided for the "q" parameter says that we can use NOT (-) and OR (|) operator in the search:
https://developers.google.com/youtube/2.0/reference#qsp
Example: q=boating%7Csailing does a search for either boating or sailing.
I am able to understand these points. My question is I am using ZendGData library in Zend Framework 2 to search the videos. I am not sure how to provide multiple keywords for the search.
$yt = new ZendGData\YouTube();
$query = $yt->newVideoQuery();
All the combinations that I tried is provided below. None of them works.
$query->setQuery("french,tamil");
$query->setQuery("french|tamil");
$query->setQuery("french%7Ctamil");
$query->setQuery("french or tamil");
Note: The docs says to use url encode so that the pipe symbol is encoded. That's why I treid %7C in the search.
The URL generated by the ZendGData class is:
https://gdata.youtube.com/feeds/api/videos?q=french|tamil&start-index=58&max-results=50&safeSearch=none&orderby=viewCount&format=5&v=2
This does not fetch the videos with keyword "tamil". All the videos are from the first keyword only.
Please point me in the correct direction.
Or this with a simple space. Tested it and it found all the keywords https://gdata.youtube.com/feeds/api/videos?q=french%20tamil&start-index=1&max-results=50&safeSearch=none&orderby=viewCount&format=5&v=2
So try this $query->setQuery("french tamil"); or $query->setQuery(urlencode(("french tamil"));
Also your start-index looks strange and should that not be start-index=1

Parsing Bing News Search API Results

Hey i am trying to parse Bing News API Search results, using Regex but finding it real hard. Can any one tell how to extract - 1. Snippet, 2. URL and 3. Name from all the results(10 is the default number) that are returned in one response ?
This is the response that i am receiving from Bing for a query.(there are 5 results returned in this)
http://ideone.com/yd8yl
You don't need to use a regular expression for parsing the Bing response. The response is in JSON (JavaScript Object Notation) format, and depending on your programming environment, you may use an appropriate library to parse it. Please check http://www.json.org/ if you are not familiar with what JSON is.

How does a website know the Google query I used to find it?

When I search for something such as "rearrange table columns in asp.net" on Google, and click the link to Wrox's forum site, the site greets me with a message such as "Your Google search for 'rearrange table columns in asp.net' brought you to Wrox Forum...".
How does a site know what query I typed into Google? And how could I add such an ablity to my site?
It is parsing your query from the query parameters in the HTTP_REFERER server variable, which contains the URL you're coming from and is provided in your HTTP request.
It uses a header known as the "HTTP referrer". See http://en.wikipedia.org/wiki/HTTP_referrer
To use it in your site, you would need some kind of dynamic page generation, such as ASP / ASP.NET, PHP, or Perl. For example in Perl, you could do something like:
if ($ENV{HTTP_REFERER} =~ /google.com\?.+&q=(.+?)&/)
print "Your google search of $1 brought you to this site";
WARNING: The code above is only an example and may not be correct or secure!
Like these guys are suggesting, it's the HTTP_REFERER header variable. The query is in the "q" key in the URL. So if you want to parse that, you can just sort out the querystring and URL decode the "q" variable.
It looks at the referrer header. Here is some fairly basic PHP code to do it.

Resources