Mark Henry
Mark Henry

Reputation: 2709

Twitter and Oauth results in 401 error

I am using Oauth to connect to Twitter, but it results in a 401 error. What am I doing wrong here?

//config
define('CONSUMER_KEY',"");
define('CONSUMER_SECRET',"");
define('OAUTH_TOKEN',"1U");
define('OAUTH_TOKEN_SECRET',"");

require_once('twitteroauth/twitteroauth.php');

$connection = new TwitterOAuth (CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET);

$connection->post('statuses/update', array('status' => 'testing'));

$httpc = $connection->http_code;
if($httpc == 200) {
echo 'succesvol';
} else {

echo $httpc;
} 

Upvotes: 2

Views: 1363

Answers (1)

Pure.Krome
Pure.Krome

Reputation: 87047

You get a 401 (Not Authorised) error when you do not provide the correct ConsumerKey and ConsumerSecret values.

Looking at the code above, you are passing empty string values for those two variables. Unless you left them out on purpose, you need to double check your values.

For my app, this is where they exist.

(ASSUMPTION: you've created a Twitter application @ dev.twitter.com)

enter image description here

Upvotes: 4

Related Questions