简体   繁体   中英

Completely stuck trying to use Abraham Williams Twitter API libraries

I'm working through Sam's Teach Yourself Twitter API.. In Hour 8, there are simple instructions of setting up the consumer key, consumer secret (I already had a different php program using these succesfully) and using Abraham Williams libraries. I plugged the key,secret into config.php, used the define('OAUTH_CALLBACK', 'http://localhost/callback.php'); with localhost and created a tinyurl for it (the work around if localhost doesnt work. Get the sign in to Twitter screen and then it goes to the redirect page that says:

“Could not connect to Twitter. Refresh the page or try again later.”

I'm completely dead in the water here. Once I get this working, I'll be off and running, but I'm completely stuck. Any help would be appreciated.

(In reponse to your questions:)

They have a config.php file where they say to put in the KEY and SECRET, which I've done:

define('CONSUMER_KEY', 'KEY');
define('CONSUMER_SECRET', 'SECRET');
define('OAUTH_CALLBACK', 'http://localhost:8888/abeoauth/connect.php');

They book says to run index.php. Here's code from that:

/* Load required lib files. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');

/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) ||     empty($_SESSION['access_token']['oauth_token_secret'])) {
    header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];

/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,     $access_token['oauth_token'], $access_token['oauth_token_secret']);

/* If method is set change API call made. Test is called by default. */
$content = $connection->get('account/verify_credentials');

Starting at index.php, like the book says, it does redirect to the "connect.php" page so it's as if I've put nothing in for the KEY variables at all..

Ok guys. Looks like it didn't like the "twitter application"(credentials) that I'd created for a different script (that worked btw). I had to create a new one just for this book example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM