OAuth connects via localhost, fails on live version?

@ToryWaterman Tory Waterman

It seems to be a problem with redirect.php not grabbing the access token properly. I've browsed around and found that lots of people have this problem but I can't figure out how to resolve it. This same code works on localhost but fails on my live version. Any ideas why/how to fix it? Is there a way I can manually set these?

/* Start session and load library. */

/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);

/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);

/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

/* If last connection failed don't display authorization link. /
switch ($connection->http_code) {
case 200:
/ Build authorize URL and redirect user to Twitter. /
$url = $connection->getAuthorizeURL($token);
header('Location: ' . $url);
/ Show notification if something went wrong. */
echo 'Could not connect to Twitter. Refresh the page or try again later.';

2 years 36 weeks ago


@ToryWaterman Tory Waterman

Some clarification: On localhost, everything works just fine. On my live version, I have a separate application with the proper keys, callbacks, etc set properly. However, when I try to use OAuth on my live version, I get the error "Could not connect to Twitter. Refresh the page or try again later."

2 years 36 weeks ago
@gerbenjacobs Gerben Jacobs

What value do you get from "$connection->http_code"
Also, shouldn't you 'break;' the default case too?

2 years 36 weeks ago
@Alilivea1 سيد علي موسوی

 & tags. Many
languages are supported like

  1. , <xml>, <html>,
  2. <ruby>, <php>, <python>...
1 year 28 weeks ago