OAuth: "Error: Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)"


#1

Hi together,

I am a newbie to twitter API. And it is the same with all API: once you get it, its easy. But I didn’t get it until now.

I have a website (www.meier-krantechnik.de) that should tweet when a new crane is for sale. Currently my PHP application fails during requesting a request token. Here my PHP code:

$config -> social_app_id = "consumer key";
$config -> social_app_secret = "consumer secret";

// get our request token
try {
	$oauth = new OAuth($config -> social_app_id, $config -> social_app_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
	// Generate request token
	$request_token_info = $oauth -> getRequestToken('https://twitter.com/oauth/request_token');
}
catch(OAuthException $e) {
	print "Error: ". $e -> getMessage() ."<br />";
}	 

The following exception is caught: “Error: Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)”

I found this code snippet here: http://toys.lerdorf.com/archives/50-Using-pecloauth-to-post-to-Twitter.html.

Can anyone help me what went wrong? Or do I have to start another way?

Any hints are welcome. Thanks in advance!

Tobias


#2

Here are some tips for troubleshooting OAuth problems: [node:204]

I would recommend using a different PHP OAuth library like tmhOAuth – the post you’re referencing is from several years ago and is likely out of date.


#3

Hi Taylor,

sorry for my late answer. Our internet connection was broken.

I already used a PHP OAuth library: abraham-twitteroauth. But that one was not the best for me, because my server brings along OAuth and there were complecations.

Now I gave tmhOAuth a try. It seems to work with the OAuth of my server. And I even get a request token!

Thus thanks for your help! I think other questions will raise. I’ll come back in case I don’t get it working!

Thanks again and greetings,

Tobias