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


#1

I am not a Programmer so Please be patient with me.

Back in 2010 I hired a programmer to implement a project where any activity conducted on my website will show in my users twitter feed.
Basically the user would link their accounts on my website to their twitter account so the activity on my website appears in their twitter feed.
The activity included the user listening to music,downloading music,adding friends etc.

Now when I try to link my account from my website to my twitter account I gets the below error
"Could not connect to Twitter. Refresh the page or try again later".

My programmer is saying that twitter has since changed their api since 2010 and thats why this error is appearing.
I want to know if this error correlates to twitter changing their api and if it is what all do I need to change (code wise) on my website to accomodate this change by twitter.

Any assistance on this matter would be greatly appreciated.

Reggie


#2

“Could not connect to Twitter. Refresh the page or try again later” is not an error message generated by Twitter, so it’s impossible to say why this may be generated. It is also not possible to suggest what might be needed to change without knowing which API endpoints your application is using, or seeing the error responses Twitter may be sending back to your app.


#3

Below is the code I am using for the application. Where can I go to see the error responses Twitter are sending back to my app??

<?php require_once('../common/configs/config.inc.php'); $CFG['mods']['is_include_only']['html_header'] = false; $CFG['html']['is_use_header'] = false; $CFG['mods']['is_include_only']['html_header'] = false; $CFG['html']['is_use_header'] = false; require($CFG['site']['project_path'].'common/application_top.inc.php'); require '../common/classes/twitter/twitteroauth.php'; define('CONSUMER_KEY', $CFG['social_connect']['twitter_consumer_key']); define('CONSUMER_SECRET', $CFG['social_connect']['twitter_consumer_secret']); if(strstr($url, "www.")) { define('OAUTH_CALLBACK', 'http://www.uwmixradio.com/members/twitterConnect.html?f=callback'); } else { define('OAUTH_CALLBACK', 'http://uwmixradio.com/members/twitterConnect.html?f=callback'); } $social = new SocialConnect(); $function = $_REQUEST['f']; if($function == "callback") { $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); $_SESSION['access_token'] = $access_token; unset($_SESSION['oauth_token']); unset($_SESSION['oauth_token_secret']); if (200 == $connection->http_code) { $access_token = $_SESSION['access_token']; $info = $connection->get('account/verify_credentials'); $social->insertTwitterLink($access_token['oauth_token'], $access_token['oauth_token_secret'], $info->screen_name); echo "You have successfully connected your account with Twitter. Please close this window."; } else { echo 'Could not connect to Twitter. Refresh the page or try again later.'; } } elseif($function == "unlink") { if($social->chkTwitterStatus()) { $social->deleteTwitterToken(); echo "Your Twitter account has successfully been unlinked. Please close this window."; } else { echo "You have no linked your Twitter account, therefore you cannot unlink one from your account."; } } else { $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET); $request_token = $connection->getRequestToken(OAUTH_CALLBACK); $_SESSION['oauth_token'] = $token = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; switch ($connection->http_code) { case 200: $url = $connection->getAuthorizeURL($token); header('Location: ' . $url); break; default: echo 'Could not connect to Twitter. Refresh the page or try again later.'; } } ?>

#4

Looks like the error is printed after either:

if (200 == $connection->http_code) { or switch ($connection->http_code) {

If you could let us know the actual value of http_code it may be useful. The response body would be more useful, but it doesn’t appear that TwitterOAuth gives you an easy way to acces this information :frowning:

I would say a place to look may be that your server time has gotten out of sync with Twitter’s servers. Make sure that the server time is synchronized with NTP.