Created
July 7, 2011 12:39
-
-
Save chebyte/1069420 to your computer and use it in GitHub Desktop.
generate valid token for youtube
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'oauth' | |
KEY = "key" | |
SECRET = "secrect" | |
consumer = OAuth::Consumer.new(KEY, SECRET, { | |
:site=>"https://www.google.com", | |
:request_token_path=>"/accounts/OAuthGetRequestToken", | |
:authorize_path=>"/accounts/OAuthAuthorizeToken", | |
:access_token_path=>"/accounts/OAuthGetAccessToken"}) | |
request_token = consumer.get_request_token( | |
{:oauth_callback => "http://example.com" }, | |
{:scope => "http://gdata.youtube.com"}) | |
puts request_token.token # The request token itself | |
puts request_token.secret # The request tokens' secret | |
puts request_token.authorize_url # The authorization URL at Google | |
#before this you have to go to authorize url and get the oauth verifier from url | |
# Recreate the (now authorized) request token | |
token = OAuth::RequestToken.new(consumer, | |
'request token', | |
'request token secrect') | |
# Swap the authorized request token for an access token | |
atoken = token.get_access_token( | |
{:oauth_verifier => 'request verifier token' }) | |
access_token = OAuth::AccessToken.new(consumer, atoken.token, atoken.secret) | |
puts atoken.token | |
puts atoken.secret | |
puts access_token.get("http://gdata.youtube.com/feeds/api/users/default").body |
you have the way to use this script here
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm a bit confused on how this is supposed to be run. With only the key, secret, and callback URL immediately available, running this whole script at once successfully produces a request token, request secret, and a Google authorization URL, but every time I go to said authorization URL, it says its malformed. Temporarily commenting out everything after line 23 makes the authorization URL work when I run it, but running it again after including the oauth_verifier just resets the request token and I get a 400 Bad Request (OAuth::Unauthorized) error. :/