How do I make the twitter search with the rest API? - twitter

when I write this
https://api.twitter.com/1.1/search/tweets.json?q=%23baseball&result_type=recent to search for #baseball but then I get a Bad Authentication data.
How do I add the Authentication to the request? I'm asking how do I make the request? Could someone give me an example of how it would look? If I have a Consumer Key and an Access Token?

The 1.1 API assures that all requests made to Twitter are made with some sort of authentication. To try out the API, use the API console here: https://apigee.com/console/twitter
To simply browse the request, use one of the auth methods in the console and pass in your request with GET https://api.twitter.com/1.1/search/tweets.json?q=baseball&result_type=recent

Related

swagger UI passing headers to API try out calls programmatically

All our services require an authentication token to be passed in a header. I know the correct way to go about that would be to use oauth but its not yet supported for our use case.
What I want to do is to get the token once by making a call to authentication service and then set it for all try out requests from swagger UI index page. There is enough documentation on how to pass a custom header to swagger API calls (the calls to get API info) but I couldn't find anything which would set a custom header for all the "try out" calls.
I will appreciate any advise.
Thanks,
Jas

OAuth2 Requesting and Storing Token

This is probably a simple question but I can't seem to wrap my head around on how OAuth2 works. So I got upto the point where I can request a token and start pulling data in Ruby console. But after I exit out of Ruby console, I tried requesting data (.rb script) from API again using the same token but it says expired/invalid. Am I suppose to store this token somewhere permanently like in a database or cookie?
Not sure if this matters but when I request a token, it brings me to the OAuth2 page to allow or deny a token request. How do you bypass this in Ruby code? From what I'm reading, you use the token.refresh! method?
Can you please share your insights on what I'm not understanding or missing?

How to pass facebook access token via AFNetworking

I am trying to make a GET request with AFNetworking to facebook's graph api. For various reasons, I'd rather not use the facebook SDK's native objects and would prefer to make those requests via AFNetworking. However, I'm a bit new to the networking side of things and I am unsure how to include the access token along with my GET request. Can anyone point me in the right direction?
I've tried setting the http header field to include this:
Authentication : {my access token}
but that doesn't seem to be working.
You need to add access_token as a URL query parameter for GET requests. See the docs here.

bad authentication data error on twitter API

I used to do the following to get user timelines:
https://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitterapi&count=2
Now that I'm switching to Twitter API 1.1, I thought all I would have to do is this:
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2
but I'm getting the bad authentication data error from Twitter. I had no authentication setup previously with twitter, does API version 1.1 require authentication?
I guess I can use the Twitter gem, looks like it makes things pretty simple. But I just want to know whether I can use the above URL like I used to!
Take a read of this. Your initial assumption is correct, authentication is now required for all endpoints in v1.1. So to answer your question your request is correct you just need to pass an OAuth token or use application-only authentication.

HTTP Get Request

I've been trying to get Rails to play with the new Facebook Graph API. After I get the authorization "code", I need to send another request which returns the access token in JSON form.
It seems to work fine, however I want to fetch the access token JSON without redirecting the user. I'm attempting to use Net::HTTP.get, but I'm not sure how to use it to get a request body, or even if it's the right thing to use to begin with.
Can anyone give an example of performing an HTTP GET?
I've figured out how to do this, the problem was mainly with the fact that I needed an HTTPS connection.
Adapted from http://snippets.dzone.com/posts/show/788:
path = '/oauth/access_token?...'
http = Net::HTTP.new('graph.facebook.com', 443)
http.use_ssl = true
res = http.get(path, nil)
#access_token = res.body
Anyone specifically trying to use the Graph API, note that the value stored in #access_token is in the form of a params string, e.g. "access_token=xxxx&expires=1234".
I got around needing to parse this by just redirecting to another page and using that as the URL params, but there's probably a better way to do this.
SOA#1
However please note that it means that server have to be log onto facebook - while if browser is redirecting it is user who have to be log into server. Hence did your server set the permission?
You can pretend that you are the user. Bad Horrible idea (you have to store passwords in cleartext on you server).
You can use OAuth. Hence you should use OAuth gem instead of Net::HTTP. You will not avoid the redirection - it is part of authorisation process and user must say that he allows to access data (imagine what would be if anyone could access anyone data on facebook). Turorial on writing OAuth clients in rails.

Resources