How to use facets and values with linkedin gem - ruby-on-rails

I am using the linkedin gem and trying to pull second degree connections only. This is said to be done by using the people search api and the network,S facet. S is for "Second degree connections."
The problem is that the documentation explains doing this with something like:
GET http://api.linkedin.com/v1/people-search?facet=network,S
I am using the linkedin gem so I tried doing something like:
client.search( { :facets => [:network, :S] }, :people )
but I get a (400): Unknown facet code {network+S}
If I change it to client.search({ facets: ["network,S"] }, :people),
I get (400): Unknown facet code {S}
If I just do client.search( { :facets => [:network] }, :people ), it returns all connections. with codes F,S,A, and O.
Any help here?
Also, when it does return, it only returns 10 or so. I saw a way to paginate through but then I have too many api calls. Is there a way to pull them all in one call?
Thanks!

Linkedin no longer supports retrieval of second level connections.
Check out this post:
Retrieve second level contacts LinkedIn API

Related

How to parse api request using ruby

I am learning how to use Yelp API from this yelp blog and yelp github on Rails. I was able to connect to Yelp service and got a response back, but I don't know what to do with the response that I got back.
Here is what I did, on Rails Console:
2.2.2 :057 > response = client.search('los angeles', {limit: 2})
=> #<Yelp::Response::Search:0x007fff32edc2c0 #region=#<Yelp::Response::Model::Region:0x007fff35ddf6d0 #span=#<Yelp::Response::Model::RegionSpan:0x007fff35ddf450 #latitude_delta=0.04455494999999132, #longitude_delta=0.02209966000000918>, #center=#<Yelp::Response::Model::RegionCenter:0x007fff35ddf5e0 #latitude=34.08390635, #longitude=-118.3184503>>,...
What kind of format is that? this article says that when I make API call to Yelp, it gives ruby object, but I am not sure what data type #<Yelp::Response... is. I guess I was expecting a ruby array/ json format return, like stated in the article:
`
search
response = client.search('San Francisco')
response.businesses
[< Business 1>, < Business 2 >, ...]
response.businesses[0].name
"Kim Makoi, DC"
response.businesses[0].rating
5.0
If I want to select a specific information, say display_address, or neighborhood from the return API, how can I do that? (Here is the end part of the same API request):
...#display_address=["6353 Yucca St", "Hollywood", "Los Angeles, CA 90028"], #geo_accuracy=8.0, #postal_code="90028", #country_code="US", #address=["6353 Yucca St"], #coordinate=#<Yelp::Response::Model::Coordinate:0x007fff35ddf7e8 #latitude=34.10413, #longitude=-118.32834>, #state_code="CA", #neighborhoods=["Hollywood"]>, #deals=nil, #gift_certificates=nil, #reviews=nil>]>
1.
If you were to call the API directly (say, from cURL), you'd get JSON back.
You're using the Yelp gem, though, so it's helpfully converting that JSON into a ruby object for you. If you're interested in the construction of the object, you can take a look at how the gem is doing the conversion on GitHub.
You should be able to interact with that response just like the article states, i.e. results.businesses should give you an array of businesses found.
More concretely, it looks like you can do something like:
results.businesses[0].display_address to get the display address for the first business found
results.businesses[0].neighborhoods is an array of all neighborhoods associated with that same business.

Timeline of search/tweets and next_results and refresh_url fileds

My web application should have next/previous results for navigating the search timeline. I already made it by using field next_resultsfor next, and pushing refresh_url into javascript array for "previous" navigating. And it worked then (3-4) days ago. After 1-2 days api calls were not returning field next_results, omitted completely, and today that field is returning same value for all "next" calls, so you are hitting next and you are refreshing the page basically. There are also fields since_id for newer and max_id for older results in search_metadata node, so I can make queries using that values... I could also get those id's from returned tweet objects, and use them, not relying on api search_metadata completely...
So I'm asking if someone already dealt with this, what is the best way to do it, not having to check code every day what twitter-api is returning? I know there is twitter support, I think there are people on this site that has done this. I also have read docs on this.
https://dev.twitter.com/docs/working-with-timelines
https://dev.twitter.com/docs/api/1.1/get/search/tweets
Here is search_metadata node example to ilustrate.
[search_metadata] => Array
(
[completed_in] => 0.057
[max_id] => 4.1747346982858E+17
[max_id_str] => 417473469828583425
[next_results] => ?max_id=416844457594855423&q=place&result_type=mixed
[query] => place
[refresh_url] => ?since_id=417473469828583425&q=place&result_type=mixed
[count] => 15
[since_id] => 0
[since_id_str] => 0
)
Ime Ime, "what is the best way to do it", not sure but this is how I used max_id
present in next_results to fetch tweets from timeline.
Twython search API with next_results
Hope it helps.

Rails TMDB API Browse to Find

TMDB.org recently made a change to their API which removes the capability to browse their database.
My Rails app used to use the tmdb-ruby gem to browse the TMDB database, but this gem only worked with v2.0 of the API, which is now defunct.
TMDB.org recommends using this gem, and since it is forked from the gem I previously used, it makes it a bit easier.
My PostgreSQL database is already populated with data imported from TMDB when v2.0 was still extant and when I could use the browse feature.
How can I now use the find feature (ie: #movie = TmdbMovie.find(:title => "Iron Man", :limit => 1) ) to find a random movie, without supplying the title of the Movie.
This is my rake file which worked with the older gem.
I would like to know how to have it work the same way but whilst using the find instead of the browse.
Thanks
I don't think find is what you need in order to get what you want (getting the oldest movies in the database and working its way up to the newest movie). Looking at the TMDb API documentation, it looks like they now have discover that may have replaced the browse that you used to use.
I don't see discover anywhere in Irio's ruby-tmdb fork, but it looks like most of the specific methods they have (like TmdbMovie.find) call a generic method Tmdb.api_call.
You should be able to use the generic method to do something like:
api_return = Tmdb.api_call(
"discover/movie",
{
page: 1,
sort_by: 'release_date.asc',
query: '' # Necessary because Tmdb.api_call throws a nil error if you don't specify a query param value
},
"en"
)
results = api_return["results"]
results.flatten!(1)
results.uniq!
results.delete_if &:nil?
results.map!{|m| TmdbMovie.new(m, true)} # `true` tells TmdbMovie.new to expand results
If this works, you could even fork Irio's fork, implement a TmdbMovie.discover method supporting all the options and handling edge cases like TmdbMovie.find does, and send them a pull request since it just looks like they haven't gotten around to implementing this yet and I'm sure other people would like to have this method as well :)

Getting total count of FB Likes for a web-app page using Rails

I am building a rails app where there is an image gallery and users will be able to hit the facebook like button for each image they open. Each image can have its seperate page URL. I plan to use the facebook like plugin so that users can like the photos as web-pages. So far I was able to find that if I do https://graph.facebook.com/?id=http://www.mysite.com/ImagePage i get:
{
"id": "http://www.mysite.com/ImagePage",
"shares": 30
}
This leaves me with 2 problems.
The shares property is not exactly the total count of likes, it is only the count of times the link made it to the user's facebook wall. How do I get the number of likes?
Is there an eventHandler or something I can use to know when a user clicks Like? so that I can store that information? I want to store the likes count at my end so that I can show the gallery in the order of descending number of total likes in each day.
I have come across the rails Koala gem but I am not sure if I need to use that for my application yet, as I do not have the need to log in users using facebook login/connect. Please advise if you think I need to do so to do what I mentioned above.
you have to use FQL.
see this example in php, im sure you know how to handle it in ruby:
$fql = 'SELECT url, share_count, like_count, comment_count, total_count
FROM link_stat WHERE url="http://stackoverflow.com"';
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
result looks like:
[
{
"url" : "http://stackoverflow.com",
"share_count" : 1353,
"like_count" : 332,
"comment_count" : 538,
"total_count" : 2223
}
]
For those who don't know how to modify the code seen in the previous answer by yourself, you mostly have two choices:
Use facebook gems available that support running FQL queries (for example: fb_graph)
Sample code:
require 'fb_graph'
array = FbGraph::Query.new(
'SELECT name FROM user WHERE uid = me()'
).fetch(ACCESS_TOKEN)
p array
Use a simple Ruby code that basically just does FQL queries, as seen on this accepted answer (Facebook FQL Query with Ruby)

Rails linkedin gem - has anyone used the search feature?

I'm trying to use the search feature of https://github.com/pengwynn/linkedin. I could not find any documentation on the search feature anywhere, not even on the gem website/github. There's some info on the profile/connections pull but nothing on the search feature.
What I want to achieve is use the gem for making a people search on linkedin. I have keywords that the user enters on my site. The keyword(s) could be the name of a person (first, last, full name), or a company name. Using these keywords I want to make a keyword search on linkedin. I'm looking for keyword matches in my first level connections, not my extended network. What I want returned is the first_name, last_name, headline, and url of my connection. I guess something like this..
client.search(:keyword => "microsoft", :fields => ["first_name", "last_name", "headline", "picture_url"])
Thanks.
For the fields you need to do something like:
:fields => [:people => ["first-name", "headline"]]
Well, I'm not a Ruby programmer, so that could be totally bogus syntax. And I've not used this gem.
But the key is that you're asking a nested set of result fields, so you need to generate a REST URL that looks like:
http://api.linkedin.com/v1/people-search:(people:(first-name,headline))?keywords=homer%20simpson
And what you are asking for is ...people-search:(first-name,headline)?....

Resources