尝试使用rest_client在Facebook API上执行简单的GET HTTP请求,但它不接受该URL,即使该URL工作正常

发布于 2024-09-30 13:26:41 字数 691 浏览 8 评论 0原文

我正在尝试获取此网址处的数据:

https://graph.facebook.com/me?access_token=(my access token)

当我在浏览器中访问此地址时,它可以工作。但我正在尝试在 Ruby on Rails 中使用 rest-client gem,如下所示:

url = 'https://graph.facebook.com/me/home?access_token=' + access_token
result = RestClient.get url
p result

但是我收到此错误消息:

URI::InvalidURIError in AuthenticationsController#index
bad URI(is not URI?): https://graph.facebook.com/me/home?access_token=(my access token)

我在这里做错了什么?会不会和access_token的格式有关系?我在上面的代码中省略了它,但这就是它的格式:

1xxx

感谢您的阅读。

I'm trying to get the data at this url:

https://graph.facebook.com/me?access_token=(my access token)

When I go to this address in a browser, it works. But I'm trying to use the rest-client gem in Ruby on Rails like this:

url = 'https://graph.facebook.com/me/home?access_token=' + access_token
result = RestClient.get url
p result

But I get this error message:

URI::InvalidURIError in AuthenticationsController#index
bad URI(is not URI?): https://graph.facebook.com/me/home?access_token=(my access token)

What am I doing wrong here? Could it have something to do with the format of the access_token? I've left it out in the code above, but this is the format it's in:

1xxx

Thanks for reading.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄人书 2024-10-07 13:26:41

尝试转义 access_token

url = 'https://graph.facebook.com/me/home?access_token=' + URI.escape(access_token)

Try escaping the access_token:

url = 'https://graph.facebook.com/me/home?access_token=' + URI.escape(access_token)
衣神在巴黎 2024-10-07 13:26:41
r = RestClient.get 'https://graph.facebook.com/me/feed', :params => {:access_token => access_token }

你应该做这样的事情

r = RestClient.get 'https://graph.facebook.com/me/feed', :params => {:access_token => access_token }

You should do something like this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文