▼参考にしている記事は以下です。
https://fromatom.hatenablog.com/entry/2022/01/30/190942
以下のコードのputs request_token.authorize_url
のところがnil
になります。
欲しいのは、認証するためのURLです。認証自体はうまくいっているように見受けられます。
ruby
1class WordpressClient 2 WP_CLIENT_KEY = ENV['WP_CLIENT_KEY'].freeze 3 WP_SECRET_KEY = ENV['WP_SECRET_KEY'].freeze 4 WP_OAUTH_ENDPOINT = ENV['WP_OAUTH_ENDPOINT'].freeze 5 WP_REQUEST_TOKEN_PATH = ENV['WP_REQUEST_TOKEN_PATH'].freeze 6 WP_AUTHORIZE_PATH = ENV['WP_AUTHORIZE_PATH'].freeze 7 WP_ACCESS_TOKEN_PATH = ENV['WP_ACCESS_TOKEN_PATH'].freeze 8 WP_CALLBACK_URL = ENV['WP_CALLBACK_URL'].freeze 9 10 class << self 11 def post 12 fetch(:post) 13 end 14 15 private 16 17 def fetch(method, headers = {}) 18 response = begin 19 consumer = OAuth::Consumer.new( 20 WP_CLIENT_KEY, 21 WP_SECRET_KEY, 22 site: WP_OAUTH_ENDPOINT, 23 request_token_path: WP_REQUEST_TOKEN_PATH, 24 authorize_path: WP_AUTHORIZE_PATH, 25 access_token_path: WP_ACCESS_TOKEN_PATH 26 ) 27 request_token = consumer.get_request_token(oauth_callback: WP_CALLBACK_URL) 28 puts request_token.authorize_url 29 oauth_verifier = Readline.readline("oauth_verifier >") 30 access_token = request_token.get_access_token(oauth_verifier: oauth_verifier) 31 binding.pry 32 rescue RestClient::ExceptionWithResponse => e 33 e.response 34 end 35 if response.code == 200 36 JSON.parse(response) 37 else 38 nil 39 end 40 rescue => e 41 nil 42 end 43 end 44end 45
request_token
の値は以下になります。
ruby
1=> #<OAuth::RequestToken:0x0000000110e52868 2 @consumer= 3 #<OAuth::Consumer:0x0000000110b0b240 4 @debug_output=nil, 5 @http=#<Net::HTTP localhost:80 open=false>, 6 @http_method=:post, 7 @key="ZBQRW2E4fKam", 8 @options= 9 {:signature_method=>"HMAC-SHA1", 10 :request_token_path=>"/oauth1/request", 11 :authenticate_path=>"/oauth/authenticate", 12 :authorize_path=>"/oauth1/authorize", 13 :access_token_path=>"/oauth1/access", 14 :proxy=>nil, 15 :scheme=>:header, 16 :http_method=>:post, 17 :debug_output=>nil, 18 :body_hash_enabled=>true, 19 :oauth_version=>"1.0", 20 :site=>"http://localhost/hoge"}, 21 @secret="ZahmImS0oMeOFj8BJPjMFEHmOPyAWkyhhgk2XfDGwuWk4pDN">, 22 @params= 23 {:"<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\noauth_token"=> 24 "FZjRlE1sNE5M7s64iC2aEgB6", 25 "<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\n<br />\n<b>Warning</b>: WP_REST_OAuth1::normalize_parameters(): Argument #2 ($value) must be passed by reference, value given in <b>/Users/hoge_name/Dropbox/Sites/hoge/wp-content/plugins/rest-api-oauth1/lib/class-wp-rest-oauth1.php</b> on line <b>672</b><br />\noauth_token"=> 26 "FZjRlE1sNE5M7s64iC2aEgB6", 27 :oauth_token_secret=>"mXyEjnDNl2zWEL7Tj31ImGmyYxKtV3I7UJTE3FXxTljjPeQH", 28 "oauth_token_secret"=>"mXyEjnDNl2zWEL7Tj31ImGmyYxKtV3I7UJTE3FXxTljjPeQH", 29 :oauth_callback_confirmed=>"true", 30 "oauth_callback_confirmed"=>"true"}, 31 @secret="mXyEjnDNl2zWEL7Tj31ImGmyYxKtV3I7UJTE3FXxTljjPeQH", 32 @token=nil>

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。