Samuel Asor
Samuel Asor

Reputation: 480

Why is requesting for authorization of my Twitter app for a new user generating a PIN?

I've created a twitter app and I have all the credentials (access token, secret, consumer key and secret). I'm using Abraham's Twitter Oauth. I've been able to get the application running but I am currently unable to Authorize a new account successfully. Instead, it is requesting for a new user to input a PIN generated after the user has granted access, before the authorization is complete. See Image

I've done some lookup on the internet and it pointed out to Twitter.com's manual here and here. From what I've been able to read up, Implementing a desktop sign in request requires oauth_callback value. I've tried to add a value to this parameter, but it returns an error: Fatal error: Uncaught exception 'Abraham\TwitterOAuth\TwitterOAuthException' with message '<?xml version="1.0" encoding="UTF-8"?> <hash> <error>Desktop applications only support the oauth_callback value 'oob'</error> <request>/oauth/request_token</request> </hash> ', but if I don't add a value to the oauth_callback parameter, it redirects to Twitter.com's authorization page successfully, but then, generates a PIN which will be required to be filled in the application. I sincerely do not know how to go round this, any help will be much appreciated. Here's my code below:

require_once "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
//Check if form was submitted
if(isset($_GET['activate-account']) && $_GET['activate-account'] == 'true'){
session_start();

//Get App Details (Consumer key and secret) from DB
$appID = 1;
$consumerKey = getAutoTweetPart($appID, 'consumer_key');
$consumerSecret = getAutoTweetPart($appID, 'consumer_secret');

$callBack = '';

$connection = new TwitterOAuth($consumerKey, $consumerSecret);

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

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

$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
header('Location: '. $url);
}

Upvotes: 1

Views: 2149

Answers (1)

Yuri Schimke
Yuri Schimke

Reputation: 13448

You should check that your app (linked from https://apps.twitter.com) has a callback URL specified, so that you are not using desktop mode. The callback URL should not be locked unless it is always the same e.g. constant host/port.

Then your request_token call can specify the URL you want the user redirected to.

This is part of the flow described here https://dev.twitter.com/web/sign-in/implementing

Upvotes: 2

Related Questions