Twitter OAuth错误401使用php oauth_service

时间:2011-08-02 12:14:24

标签: php twitter oauth twitter-oauth

当我使用由oauth项目oauth 1.2.2的源代码提供的twitter示例代码时,我在重定向后收到401 HTTP失败。重定向URL通过没有NAT的外部IP登陆我的本地主机。我如何让这个例子有效?

这是示例

提供的代码
$oauth = new OAuth(TWITTER_CONSUMER_KEY,TWITTER_CONSUMER_SECRET,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
/* Uncomment the line below to get lots of debug */
$oauth->enableDebug();
$request_token_info = $oauth->getRequestToken(TWITTER_REQUEST_TOKEN_URL);
printf("I think I got a valid request token, navigate your www client to:\n\n%s?oauth_token=%s\n\nOnce you finish authorizing, hit ENTER or INTERRUPT to exit\n\n", TWITTER_AUTHORIZE_URL, $request_token_info["oauth_token"]);
$in = fopen("php://stdin", "r");
fgets($in, 255);
printf("Grabbing an access token...\n");
/* grab the access token, which is your persistent token which you use for future requests */
$oauth->setToken($request_token_info["oauth_token"],$request_token_info["oauth_token_secret"]);
$access_token_info = $oauth->getAccessToken(TWITTER_ACCESS_TOKEN_URL);

抓取访问令牌后,我收到Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect) OAuthException。

0 个答案:

没有答案