Twitteroauth回调不会重定向到正确的位置 [英] Twitteroauth callback not redirecting to correct location

查看:89
本文介绍了Twitteroauth回调不会重定向到正确的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正试图实施twitteroauth从twitter登录。到目前为止,我已将消费者密钥和密码发送到Twitter,页面显示了Twitter用户可以授权或拒绝访问他们来自的网站。



但是,当我从api.twitter.com点击授权时,网址不正确。网址如下所示:



https://api.twitter.com/oauth/OAUTH_CALLBACK?oauth_token=XXXXXXXXXXXXXXXX&oauth_verifier=XXXXXXXXXXXXXXXXXXXXXXXXXX



我认为我不想在网址中使用api.twitter.com/oauth/部分,因为我只想让它转到指定的回调。



Config.php:



 <?php  
define(' CONSUMER_KEY'' XXXXXXXXXXXXXXXXXXXXXXXXX');
define(' CONSUMER_SECRET'' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
define(' OAUTH_CALLBACK'' www.example.co.uk/twitter/twitter_oauth.php');
?>







twitter_oauth.php:



 require '  config.php中; 
需要' autoload.php';
使用Abraham \TwitterOAuth \TwitterOAuth;

session_start();

$ request_token = [];
$ request_token [' oauth_token'] = $ _SESSION [' oauth_token'];
$ request_token [' oauth_token_secret'] = $ _SESSION [' oauth_token_secret'];

$ connection = new TwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET);

$ request_token = $ connection-> oauth(' oauth / request_token',array(' oauth_callback' = > OAUTH_CALLBACK));

$ _SESSION [' oauth_token'] = $ request_token [' oauth_token'];
$ _SESSION [' oauth_token_secret'] = $ request_token [' oauth_token_secret'];

// 现在我们用用户access_token $ b创建一个TwitterOAuth实例$ b $ connection = new TwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET,$ access_token [' oauth_token'],$ access_token [' oauth_token_secret']);

// 让我们获取用户的信息
$ url = $ connection-> url(' oauth / authorize' ,array(' oauth_token' => $ request_token [' oauth_token']));





我是一个新手,所以我真的不明白什么是错的,我已经尝试修复它一段时间但我没有这样的运气,所以任何指导都会非常感激。

解决方案

request_token = [];


request_token [' oauth_token'] =


_SESSION [' 组oauth_token'];

Hi,

Im trying to implement twitteroauth for signing in from twitter. So far I have sent the consumer key and secret to twitter and the page shows where the twitter user can authorise or deny access to the website they came from.

However, when I click authorise from api.twitter.com, the url isnt correct. the url looks like the following:

https://api.twitter.com/oauth/OAUTH_CALLBACK?oauth_token=XXXXXXXXXXXXXXXX&oauth_verifier=XXXXXXXXXXXXXXXXXXXXXXXXXX

I presume i dont want the api.twitter.com/oauth/ part in the url as i just want it to go to the callback that is specified.

Config.php:

<?php
define('CONSUMER_KEY', 'XXXXXXXXXXXXXXXXXXXXXXXXX');
define('CONSUMER_SECRET', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
define('OAUTH_CALLBACK', 'www.example.co.uk/twitter/twitter_oauth.php');
?>




twitter_oauth.php:

require 'config.php';
require 'autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;

session_start();

$request_token = [];
$request_token['oauth_token'] = $_SESSION['oauth_token'];
$request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);

$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));

$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

//Now we make a TwitterOAuth instance with the users access_token
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

// Let's get the user's info
$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));



Im a newbie at this so I cant really understand whats going wrong, Ive tried fixing it for a while but I'm having no such luck, so any guidance would be much appreciated.

解决方案

request_token = [];


request_token['oauth_token'] =


_SESSION['oauth_token'];


这篇关于Twitteroauth回调不会重定向到正确的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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