Created
April 8, 2020 15:24
-
-
Save vaiorabbit/7562f244c4fc49d90a17cf0371ad5413 to your computer and use it in GitHub Desktop.
Twitter 'POST favorites/destroy' API
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
#! /usr/bin/env ruby | |
# coding: utf-8 | |
# Usage: | |
# - Set environment variables 'TWITTER_CONSUMER_KEY', 'TWITTER_CONSUMER_SECRET', 'TWITTER_ACCESS_TOKEN' and 'TWITTER_ACCESS_TOKEN_SECRET' beforehand | |
# - $ ruby destroy_like.rb [tweet id] | |
# Ref.: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-destroy | |
require 'json' | |
require 'oauth' | |
consumer_key = ENV['TWITTER_CONSUMER_KEY'] | |
consumer_secret = ENV['TWITTER_CONSUMER_SECRET'] | |
access_token = ENV['TWITTER_ACCESS_TOKEN'] | |
access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET'] | |
consumer = OAuth::Consumer.new( | |
consumer_key, | |
consumer_secret, | |
site:'https://api.twitter.com/' | |
) | |
endpoint = OAuth::AccessToken.new(consumer, access_token, access_token_secret) | |
destroy_id=ARGV[0] | |
response = endpoint.delete("https://api.twitter.com/1.1/favorites/destroy.json?id=#{destroy_id}") | |
json = JSON.parse(response.body) | |
File.open("result.json", "w") do |f| | |
f.write(JSON.pretty_generate(json)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment