将状态发布到 Twitter。浏览器与代码
我正在尝试向 Twitter 发布状态更新。我编写了一个 API 调用,以便当我执行
http://.....&token=< /a>$token&s=$token_secret&msg=hello ...当我在浏览器中输入 URL 时,它工作正常。状态已正确发布。
但是,当我想通过 file_get_contents($url) 发布状态(其中 $url 与浏览器的工作方式相同)时,我收到“无法打开流:HTTP 请求失败!HTTP/1.0 401 未经授权”
我测试了一下,和url编码无关。我这样做是正确的。
那么有谁知道为什么它通过浏览器起作用,而不是通过代码起作用? Twitter 是否会阻止非浏览器用户代理?
非常感谢您的帮助。
I am trying to post a status update to Twitter. I wrote an API call so that when I do
http://.....&token=$token&s=$token_secret&msg=hello ...it works fine when I type the URL into the browser. The status is posted correctly.
However, when I want to post the status via file_get_contents($url) where the $url is the same as how it worked from the browser, I receive a "failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized"
I did some tests, and it has nothing to do with url encoding. I am doing that properly.
So does anyone know why it works through the browser, but not through the code? Does Twitter block non-browser user agents?
Thanks a lot for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来好像当您在浏览器中尝试时,您是以自己的身份登录的,因此您的帖子正在通过。但是,当您在代码中运行它时,它不会发送您的 cookie,因此不会登录,因此无权发布。
您的代码是否正在尝试登录?
Sounds like when you try it in the browser, you are logged in as yourself, so your post is going through. However, when you run it in your code, it doesn't send your cookies, so is not logged in, and therefore is not authorized to post.
Is your code attempting to log in at all?