Created
December 21, 2014 13:56
-
-
Save uzimith/9a528edb820cd3d70f62 to your computer and use it in GitHub Desktop.
[test] アカウント停止したチャンネルがAPIで取得できなかった
This file contains hidden or 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
# A sample Gemfile | |
source "https://rubygems.org" | |
gem "google-api-client" | |
mem "thin" |
This file contains hidden or 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 'thin' | |
require 'launchy' | |
require 'google/api_client' | |
require 'google/api_client/client_secrets' | |
# Small helper for the sample apps for performing OAuth 2.0 flows from the command | |
# line. Starts an embedded server to handle redirects. | |
class CommandLineOAuthHelper | |
def initialize(scope) | |
credentials = Google::APIClient::ClientSecrets.load | |
@authorization = Signet::OAuth2::Client.new( | |
:authorization_uri => credentials.authorization_uri, | |
:token_credential_uri => credentials.token_credential_uri, | |
:client_id => credentials.client_id, | |
:client_secret => credentials.client_secret, | |
:redirect_uri => credentials.redirect_uris.first, | |
:scope => scope) | |
end | |
# Request authorization. Opens a browser and waits for response | |
def authorize | |
auth = @authorization | |
url = @authorization.authorization_uri().to_s | |
server = Thin::Server.new('0.0.0.0', 3000) do | |
run lambda { |env| | |
# Exchange the auth code & quit | |
req = Rack::Request.new(env) | |
auth.code = req['code'] | |
auth.fetch_access_token! | |
server.stop() | |
[200, {'Content-Type' => 'text/plain'}, 'OK'] | |
} | |
end | |
Launchy.open(url) | |
server.start() | |
return @authorization | |
end | |
end |
This file contains hidden or 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 'pry-byebug'; | |
require 'google/api_client' | |
# The oauth/oauth_util code is not part of the official Ruby client library. | |
# Download it from: | |
# http://samples.google-api-ruby-client.googlecode.com/git/oauth/oauth_util.rb | |
require_relative "oauth_util" | |
# This OAuth 2.0 access scope allows for full read/write access to the | |
# authenticated user's account. | |
YOUTUBE_SCOPE = 'https://www.googleapis.com/auth/youtube' | |
YOUTUBE_API_SERVICE_NAME = 'youtube' | |
YOUTUBE_API_VERSION = 'v3' | |
client = Google::APIClient.new({ | |
application_name: "uzimy-libyoutube", | |
application_version: "v0.0.1" | |
}) | |
youtube = client.discovered_api(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION) | |
auth_util = CommandLineOAuthHelper.new(YOUTUBE_SCOPE) | |
client.authorization = auth_util.authorize() | |
# Call the API's youtube.subscriptions.insert method to add the subscription | |
# to the specified channel. | |
begin | |
subscriptions = client.execute!( | |
api_method: youtube.subscriptions.delete, | |
parameters: { | |
id: "UCdBeQ_DQTHFgT-4DRJmeR4A" | |
}, | |
) | |
p subscriptions | |
rescue Google::APIClient::ClientError => e | |
puts "#{e} : error" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment