简体   繁体   English

PHP OAuth,代理后面有Twitter

[英]PHP OAuth with twitter behind a proxy

I am currently using php oauth to connect my site with twitter, but the problem is that my machine is behind a proxy and I got the error 我目前正在使用php oauth将我的网站与Twitter连接,但是问题是我的机器位于代理之后,并且出现了错误

OAuth::getRequestToken(https://api.twitter.com/oauth/request_token): failed to open stream: Network is unreachable

How can I do configuration in such case? 在这种情况下如何配置? Thanks a lot. 非常感谢。

I have been trying to do much the same. 我一直在尝试做同样的事情。

There appears to be no way to expose the curl object used by the oauth library in order to set the options put forward by Avanche. 似乎没有办法公开oauth库使用的curl对象来设置Avanche提出的选项。

It's possible to change the oauth lib from using curl to use streams instead. 可以将oauth库从使用curl改为使用流。 This opens the possibility of setting the default stream context options to use your proxy, then letting oauth use that. 这样就可以设置默认流上下文选项以使用代理,然后让oauth使用它。

http://www.php.net/manual/en/oauth.setrequestengine.php http://www.php.net/manual/en/oauth.setrequestengine.php

http://uk3.php.net/manual/en/function.stream-context-set-default.php http://uk3.php.net/manual/en/function.stream-context-set-default.php

This sounds like it should work, but our configuration consistently gave "400 - Bad request" errors. 听起来应该可以,但是我们的配置始终显示“ 400-错误的请求”错误。 This is probably a problem at our end, so you should have a better time with it. 这可能是我们遇到的一个问题,因此您应该拥有更好的时间。

What you need to do in this case, is find in the OAuth object where curl is configured and add the following options: 在这种情况下,您需要做的是在配置了curl的OAuth对象中找到并添加以下选项:

curl_setopt($ch, CURLOPT_PROXY, $yourproxy);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);

Answered for historical purposes 为历史目的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM