Twitter API with rails - ruby-on-rails

I'm trying call the "lookup" method on multiple users on Twitter. According to the documentation, this is feasible.
http://apiwiki.twitter.com/w/page/24142947/Twitter-REST-API-Method:-users-lookup
I'm calling the method and stringing together 5 IDs separated by commas.
Here's my call:
access_token = twitter_oauth_access_token(user.twitter.token, user.twitter.secret)
response = access_token.get("/users/lookup.json?user_id=#{ids.join(',')}")
ActiveSupport::JSON.decode(response.body)
I've verified that there are multiple IDs in the "ids" variable. The problem is that no matter how I call it, I only get the first one in the list back. So the call is successful, but it doesn't give me the list of results as the documentation says.
Any idea what I might be doing wrong?

I figured it out. The API URL was incorrect. It should've been:
access_token.get("/1/users/lookup.json?user_id=#{ids.join(',')}")
instead of
access_token.get("/users/lookup.json?user_id=#{ids.join(',')}")

Related

What's wrong with my LinkedIn API call syntax?

I'm using omniauth to access profiles, though I've setup the linkedin gem and used the access tockens from omniauth so that I can do a seperate pull to access different picture sizes.
Here's my code:
client = LinkedIn::Client.new
client.authorize_from_access(auth.extra.access_token.token, auth.extra.access_token.secret)
linkedinpicture = client.profile.picture-urls::(original)
This doesn't work, it returns an error of
undefined local variable or method 'urls'
But at the same time I know the API caller is working because if I access the users headline (client.profile.headline) instead of their picture-urls then it works fine. Is it something with the syntax that I need to format properly? I'm guessing it doesn't like the '-' character.
Here's the LinkedIn documentation I'm referencing: https://developer.linkedin.com/docs/fields/basic-profile
Any thoughts would be great.
Instead of:
linkedinpicture = client.profile.picture-urls::(original)
Try:
linkedinpicture = client.picture_urls(:id => 'id_of_connection')
See https://github.com/hexgnu/linkedin/blob/c0ec6a6960f21fcd428916c53b3c229907a7af79/lib/linked_in/api/people.rb#L56-L70 for the relevant gem code.

Api to post a comment in instagram using instagram gem?

I have tried by using the following code,
client = Instagram.client(:access_token => "My_Access_Token")
result = client.create_media_comment("Media_Id", "Comment")
but i'm getting the following error,
POST https://api.instagram.com/v1/media/Media_Id/comments.json: 400: Please visit http://bit.ly/instacomments for commenting access
How can i resolve this?
You should be passing an actual id for the piece of Instagram media on which you want to create a comment rather than the "Media_Id" string.
Your code is correct (otherwise you won't get that error).
You need to go to http://bit.ly/instacomments and ask for commenting permission. Don't expect a reply anytime soon though, I've been waiting for a reply over a month, and seen people getting replies for that after three or four months.

Does self as identifier can represent the resource on restful api?

I'm working on REST API, and I trying to understand whether this looks legit in terms of REST.
I've players which using some mobile app with a login mechanism,
So the question is, if the player needs to update some attribute on his resource,
How the URL & PARAMS should looks like:
Option #1:
PUT /api/players/59/
PARAMS { some_attribute: "some_value" }
Option #2:
PUT /api/players/self
PARAMS { some_attribute: "some_value" }
The thing is, that the player doing the call with authentication, so it looks odd that he needs to send his id, it feels like he can send update on some other id, so when he sends 'self' it looks more suitable but uglier.
What's the REST point of view here?
Or maybe another option?
You should use first option
But in first option, request additional parameter like authentication_token
to verify the user and user is updating his information only.
This gist will help you in authenticating user
https://gist.github.com/josevalim/fb706b1e933ef01e4fb6
It shows 2 method for authenticating user while communicating with API

Instagram gem: how to get next page of results?

How do I get the next page of results using the Instagram gem?
The documentation for the API itself says there is a pagination hash passed in with each result (see here: http://instagram.com/developer/endpoints/). How do I access that with the gem?
Got it. I don't think the pagination hash that Instagram passes back is accessible, but you can pass in a max_id option when querying, to get the next set of older pictures.
#results = Instagram.user_recent_media(some_user_id, {access_token: token, count: 10, max_id: 197679035065553721})
By passing in max_id (the id of a photo), it will return all results older than that. So grab the id of the oldest photo from the first query, and pass it in to get the next page.
Note: when you get the results, the ids of pictures are in the form: 197679035065553721_someuserid. You have to parse out the first bit before the underscore, and pass that in as max_id.
Instagram.tag_recent_media(params[:q]).pagination
run that code and you will see the pagination attributes.
I have looked into this for a project of my own and eventually found that you can get the client to give you the pagination info by setting no_response_wrapper to true when creating the client:
client = Instagram.client(:access_token => accesstoken,
:no_response_wrapper => true)
This makes it so you can use .pagination on the response as Yigit C. Bacakoglu suggested.
You may be out of luck. If you look through the client modules, you can see that the methods are returning the data field of the response, so the pagination field is unavailable. There's also an issue that touches on the lack of pagination info in responses.

How do I pass additional information to into ActionMailer to handle incoming messages?

I have an application that checks multiple email accounts (think Webmail). Because I'm retrieving multiple accounts, I need to associate the inbound email with a user's account. However, I can't seem to find a way to do this.
If i pass into Fetcher a user_id in the options hash, from what I understand it creates it as an attribute. But, I'm unclear how to get the fetched message modified in such a way as to make it happy for ActionMailer. If I add an argument to the "receive" method, that fails with a message "wrong number of arguments."
If I try to modify the message retrieved, I get an error with "wrong number of arguments". And, because ActionMailer is not really a full class, I can't simply initialize it with the right data.
Any thoughts on how to pass this information?
I'll answer this because I hate not finding answers.
I wrapped ActionMailer in another class. This new class took the additional attributes and handled them. This is how I got around this problem.

Resources