Twitter O-Auth 回调 URL [英] Twitter O-Auth Callback url

查看:86
本文介绍了Twitter O-Auth 回调 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Twitter 的 oauth 身份验证和使用回调 url 时遇到问题.

I am having a problem with Twitter's oauth authentication and using a callback url.

我正在用 php 编码并使用 twitter wiki 引用的示例代码,http://github.com/亚伯拉罕/twitteroauth

I am coding in php and using the sample code referenced by the twitter wiki, http://github.com/abraham/twitteroauth

我得到了那个代码,并尝试了一个简单的测试,它运行良好.但是我想以编程方式指定回调 url,并且示例不支持.

I got that code, and tried a simple test and it worked nicely. However I want to programatically specify the callback url, and the example did not support that.

所以我迅速修改了 getRequestToken() 方法以接收一个参数,现在它看起来像这样:

So I quickly modified the getRequestToken() method to take in a parameter and now it looks like this:

function getRequestToken($params = array()) {
  $r = $this->oAuthRequest($this->requestTokenURL(), $params);
  $token = $this->oAuthParseResponse($r);
  $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
  return $token;
}

我的电话看起来像这样

$tok = $to->getRequestToken(array('oauth_callback' => 'http://127.0.0.1/twitter_prompt/index.php'));

这是我所做的唯一更改,重定向的作用就像一个魅力,但是当我尝试使用我新授予的访问权限尝试拨打电话时出现错误.我收到无法对您进行身份验证"错误.此外,该应用程序实际上从未真正添加到用户授权的连接中.

This is the only change I made, and the redirect works like a charm, however I am getting an error when I then try and use my newly granted access to try and make a call. I get a "Could not authenticate you" error. Also the application never actually gets added to the users authorized connections.

现在我阅读了规范,我认为我所要做的就是在获取请求令牌时指定参数.有人可以在 oauth 和 twitter 方面更有经验吗?谢谢

Now I read the specs and I thought all I had to do was specify the parameter when getting the request token. Could someone a little more seasoned in oauth and twitter possibly give me a hand? Thank You

推荐答案

我认为现在 twitter 已经解决了这个问题,或者您可能没有在应用程序设置中提供默认回调 url,这是动态回调 url 所必需的像上面其他人提到的那样工作.

I think this is fixed by twitter by now or you might have missed to provide a default callback url in your application settings, which is required for dynamic callback url to work as mentioned by others above.

无论如何,我通过在检索请求令牌时传递 oath_callback 参数来实现此目的.我正在使用 twitter-async PHP 库,并且必须进行一些小调整以使库通过回调网址.

Any case, I got this working by passing the oath_callback parameter while retrieving the request token. I am using twitter-async PHP library and had to make a small tweak to make the library pass the callback url.

如果您使用 twitter-async,更改如下:

If you are using twitter-async, the change is below:

修改 getRequestToken 和 getAuthenticateURL 函数,以回调 url 为参数

modified getRequestToken and getAuthenticateURL functions to take callback url as parameter

 public function getRequestToken($callback_url = null)
  {
    $params = empty($callback_url) ? null : array('oauth_callback'=>$callback_url);
    $resp = $this->httpRequest('GET', $this->requestTokenUrl, $params);
    return new EpiOAuthResponse($resp);
  }


 public function getAuthenticateUrl($callback_url = null)
  { 
    $token = $this->getRequestToken($callback_url);
    return $this->authenticateUrl . '?oauth_token=' . $token->oauth_token;
  }

并从您的 PHP 代码中传递回调 url.

And pass the callback url from your PHP code.

$twitterObj->getAuthenticateUrl('http://localhost/twitter/confirm.php');

这篇关于Twitter O-Auth 回调 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆