Msg error "Page not found" after given the authorization


#1

hi,

after given the authorisation ( https://api.twitter.com/oauth/authorize?oauth_token=eJhMacRf1Po8hoateU6jKZMhDjgjVY8i6OWHx1BqHg)

i m redirected to this url
https://api.twitter.com/login?redirect_after_login=%2Foauth%2Flibs%2Fcallback.php%3Foauth_token%3DeJhMacRf1Po8hoateU6jKZMhDjgjVY8i6OWHx1BqHg%26oauth_verifier%3D6X1YAyR7jVV0OFEmkCNLKQNNNgS70wZgvE4hLsbGI8

with error msg “sorry, page doesn’t existe”,

maybe the the generated toekns are not correct or something, Help please :slight_smile:


#2

What’s the oauth_callback value you’re passing to oauth/request_token?


#3

here is my url,
http://twitplanner.caraibes.dev/frontend_dev.php/fr/tweetlist/callback.php

but the main problem is i still don’t understand the right way to use the Callback,

as i have seen in many tuto,
step 1 getting the request_token (done fine)
step 2 getting access_token ( by using the callback)
step 3 send the tweet ( but here i don’t see where to put the function $tweet->post(‘statuses/update’, array(‘status’ => “$message”)); )

thank you very much for helping me i m stock since Monday


#4

-------------------------------- twitermanager.php
class twiterManager
{

/**
 * Obtain a request token from Twitter
 *
 * @return bool False if request failed
 */
public function getRequestToken()
{
	

	define('CONSUMER_KEY','xxxx');
	define('CONSUMER_SECRET' ,'xxxxx');
	define("OAUTH_CALLBACK", "libs/callback.php");
	
	
    

	
	
	// The TwitterOAuth instance
	$twitteroauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
	// Requesting authentication tokens, the parameter is the URL we will be redirected to/
	$urlRedi = OAUTH_CALLBACK;
	$request_token = $twitteroauth->getRequestToken($urlRedi);
	
	// Saving them into the session
	$_SESSION['oauth_token'] = $request_token['oauth_token'];
	$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
	$tweet = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
	
	if($tweet->post('statuses/update', array('status' => 'gfgtdtgdfgxcg'))): 
		//die('post');
	endif;
	//die('post');
	// If everything goes well..
	if($twitteroauth->http_code==200){
		
		// Let's generate the URL and redirect
		$url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
		header('Location: '. $url);
			
	
	} 
	//else {
		// It's a bad idea to kill the script, but we've got to know when there's an error.
		//die('Something wrong happened.');
	//}
	
	// else if something bad happend return false
	return false;
	
	
}

/**
 * Obtain an access token from Twitter
 *
 * @return bool False if request failed
 */
public function getAccessToken()
{
	
	
	 
	// TwitterOAuth instance, with two new parameters we got in twitter_login.php
	$twitteroauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
	// Let's request the access token
	$access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']);
	// Save it in a session var
	$_SESSION['access_token'] = $access_token;
	// Let's get the user's info
	$user_info = $twitteroauth->get('account/verify_credentials');
	// Print user's info
	print_r($user_info);
	 
	// Let's find the user by its ID
	 
	// If not, let's add it to the database
	 
	// Else ,Update the tokens
	  return $user_info;
	
	
//	return false;
	
}

/**
 * Send the selected tweet to the conrespandent account
 *
 * @return bool False if sending failed
 */
public function SendTweet()
{
	$twitteroauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
	$twitteroauth->post('statuses/update', array('status' => 'Bienvenue medo'));
	
	
}

}
-----------------------------------------------------------------------------the callback.php

<?php /** * @file * Take the user when they return from Twitter. Get access tokens. * Verify credentials and redirect to based on response from Twitter. */ $isLoggedOnTwitter = false; if (!empty($_SESSION['access_token']) && !empty($_SESSION['access_token']['oauth_token']) && !empty($_SESSION['access_token']['oauth_token_secret'])) { // On récupère les tokens, nous sommes identifiés. $access_token = $_SESSION['access_token']; /* On créé la connexion avec Twitter en fournissant les tokens d'accès en paramètres.*/ $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); /* On récupère les informations sur le compte Twitter du visiteur */ $twitterInfos = $connection->get('account/verify_credentials'); $isLoggedOnTwitter = true; } elseif(isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] === $_REQUEST['oauth_token']) { // Les tokens d'accès ne sont pas encore stockés, il faut vérifier l'authentification /* On créé la connexion avec Twitter en fournissant les tokens d'accès en paramètres.*/ $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); /* On vérifie les tokens et récupère le token d'accès */ $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); /* On stocke en session les tokens d'accès et on supprime ceux qui ne sont plus utiles. */ $_SESSION['access_token'] = $access_token; unset($_SESSION['oauth_token']); unset($_SESSION['oauth_token_secret']); if (200 == $connection->http_code) { $twitterInfos = $connection->get('account/verify_credentials'); $isLoggedOnTwitter = true; } else { $isLoggedOnTwitter = false; } } else { $isLoggedOnTwitter = false; } ---------------------------------------------------------- main ACTION.class.php $getrequestToken = new twiterManager(); // getting the request_token $requestToken = $getrequestToken->getRequestToken(); $tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret); // Your Message $message = "This is a test message."; // Send tweet $tweet->post('statuses/update', array('status' => "$message")); --------------------------------------------------------------------------------- But this is what i got: (the flow) i click on tweet -> redirected to the API.tweeter page to Authorize the app and then i have error message page don't existe. Please excuse my english level, and hope you got my idea so you can advice me Thanks