Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?php
define('CONSUMER_KEY', 'XXXXXXXXXXXXXXXXXXXXXXXXX');
define('CONSUMER_SECRET', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
define('OAUTH_CALLBACK', 'www.example.co.uk/twitter/twitter_oauth.php');
?>



twitter_oauth.php:

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.
Posted

1 solution

I figured it out.

The callback url has to be an actual url.

I had to put http:// At the start of my callback in config.php to define an 'actual' url and not a string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900