"undefined method `bytesize' for #"エラー。 -Instagramのプラグインが作りたい-
移転しました。
Lokkaのプラグイン hello.rb を改造してみる。試しに、Instagramのプラグインでも作ってみたいという願望。
でも、ここでエラーが。。
module Lokka module Hello def self.registered(app) app.get '/hello' do require 'uri' require 'net/https' require 'json' url = 'https://api.instagram.com/v1/users/{YOUR_ID}/media/recent' access_token = YOUR_ACCESS_TOKEN param = "access_token=#{access_token}" json = nil uri = URI.parse(url) https = Net::HTTP.new(uri.host,443) https.use_ssl = true https.start { response = https.get(uri.path + "?#{param}") json = JSON.parse(response.body) } json["data"].each do |item| print "#{item["id"]}" end end end end end
undefined method `bytesize' for #
methodがないんじゃなくて、sinatraの仕様みたい。試しに"hello"を返すようにしたらうまくいった。
Your getting this error because Sinatra takes the return value of a route and converts it into a string before trying to display it to the client.
sinatra - error happens when I try "all" method in datamapper - Stack Overflow
module Lokka module Hello def self.registered(app) app.get '/hello' do require 'uri' require 'net/https' require 'json' url = 'https://api.instagram.com/v1/users/{YOUR_ID}/media/recent' access_token = YOUR_ACCESS_TOKEN param = "access_token=#{access_token}" json = nil uri = URI.parse(url) https = Net::HTTP.new(uri.host,443) https.use_ssl = true https.start { response = https.get(uri.path + "?#{param}") json = JSON.parse(response.body) } json["data"].each do |item| print "#{item["id"]}" end "hello" end end end end