Debian Codegraph @

sample/oauth_friendfeed.rb

raw
1 require 'oauthclient'
2
3 # Get your own consumer token from http://friendfeed.com/api/applications
4 consumer_key = 'EDIT HERE'
5 consumer_secret = 'EDIT HERE'
6
7 request_token_url = 'https://friendfeed.com/account/oauth/request_token'
8 oob_authorize_url = 'https://friendfeed.com/account/oauth/authorize'
9 access_token_url = 'https://friendfeed.com/account/oauth/access_token'
10
11 STDOUT.sync = true
12
13 # create OAuth client.
14 client = OAuthClient.new
15 client.oauth_config.consumer_key = consumer_key
16 client.oauth_config.consumer_secret = consumer_secret
17 client.oauth_config.signature_method = 'HMAC-SHA1'
18 client.oauth_config.http_method = :get # FriendFeed does not allow :post
19 client.debug_dev = STDERR if $DEBUG
20
21 # Get request token.
22 res = client.get_request_token(request_token_url)
23 p res.status
24 p res.oauth_params
25 p res.content
26 p client.oauth_config
27 token = res.oauth_params['oauth_token']
28 secret = res.oauth_params['oauth_token_secret']
29 raise if token.nil? or secret.nil?
30
31 # You need to confirm authorization out of band.
32 puts
33 puts "Go here and do confirm: #{oob_authorize_url}?oauth_token=#{token}"
34 puts "Hit [enter] to go"
35 gets
36
37 # Get access token.
38 # FYI: You may need to re-construct OAuthClient instance here.
39 # In normal web app flow, getting access token and getting request token
40 # must be done in different HTTP requests.
41 # client = OAuthClient.new
42 # client.oauth_config.consumer_key = consumer_key
43 # client.oauth_config.consumer_secret = consumer_secret
44 # client.oauth_config.signature_method = 'HMAC-SHA1'
45 # client.oauth_config.http_method = :get # Twitter does not allow :post
46 res = client.get_access_token(access_token_url, token, secret)
47 p res.status
48 p res.oauth_params
49 p res.content
50 p client.oauth_config
51 username = res.oauth_params['username']
52
53 puts
54 puts "Access token usage example"
55 puts "Hit [enter] to go"
56 gets
57
58 # Access to a protected resource. (user profile)
59 puts client.get("http://friendfeed-api.com/v2/feedinfo/#{username}?format=json")