未定义方法“request_uri”使用 Rest Client 时出错 - 尝试使用 Facebook Graph 删除

发布于 2024-10-31 13:10:41 字数 1607 浏览 0 评论 0原文

我可以尝试使用 Rest Client 使用 Facebook 图

def delete_object
    temp = url_escape('https://graph.facebook.com/'+request_id+'?access_token='+token)
    p "temp is"
    p temp
    delete_attempt = RestClient.delete temp
end

private

def url_escape(string)
    string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
        '%' + $1.unpack('H2' * $1.size).join('%').upcase
    end.tr(' ', '+')
end

控制台输出:

temp is
"https%3A%2F%2Fgraph.facebook.com%2Fobject_id_here%3Faccess_token%3Daccess_token_here"

object_id_here & access_token_here 在这里用作占位符,值是正确的。

我收到此错误:

undefined method `request_uri' for #<URI::Generic:0x00000104385a40>
/Users/ben/.rvm/gems/ruby-1.9.2-p0/gems/rest-client-1.6.1/lib/restclient/request.rb:60:in `execute'\n/
Users/ben/.rvm/gems/ruby-1.9.2-p0/gems/rest-client-1.6.1/lib/restclient/request.rb:31:in `execute'\n/
Users/ben/.rvm/gems/ruby-1.9.2-p0/gems/rest-client-1.6.1/lib/restclient.rb:80

request.rb 是 Rest Client 中此方法中的 transmit uri... 行:

def execute & block
    uri = parse_url_with_auth(url)
    transmit uri, net_http_request_class(method).new(uri.request_uri, processed_headers), payload, & block
end

导致此错误的原因是什么?

I can trying to use Rest Client to delete an object using the Facebook Graph.

def delete_object
    temp = url_escape('https://graph.facebook.com/'+request_id+'?access_token='+token)
    p "temp is"
    p temp
    delete_attempt = RestClient.delete temp
end

private

def url_escape(string)
    string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
        '%' + $1.unpack('H2' * $1.size).join('%').upcase
    end.tr(' ', '+')
end

Console output:

temp is
"https%3A%2F%2Fgraph.facebook.com%2Fobject_id_here%3Faccess_token%3Daccess_token_here"

object_id_here & access_token_here used as placeholders here, the values are correct.

I get this error:

undefined method `request_uri' for #<URI::Generic:0x00000104385a40>
/Users/ben/.rvm/gems/ruby-1.9.2-p0/gems/rest-client-1.6.1/lib/restclient/request.rb:60:in `execute'\n/
Users/ben/.rvm/gems/ruby-1.9.2-p0/gems/rest-client-1.6.1/lib/restclient/request.rb:31:in `execute'\n/
Users/ben/.rvm/gems/ruby-1.9.2-p0/gems/rest-client-1.6.1/lib/restclient.rb:80

Line 60 in request.rb is the transmit uri... line in this method in Rest Client:

def execute & block
    uri = parse_url_with_auth(url)
    transmit uri, net_http_request_class(method).new(uri.request_uri, processed_headers), payload, & block
end

What is causing this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文