Gettng Invalid / expired Token error on callback after login, though tokens are valid


#1

When i log into twitter through my application, it logs fine. But, while redirecting, it is showing error Invalid / expired Token. I’ve checked tokens. But, they are valid. Here is the code that i’ve written on call back.

$twitterObj->setToken($_GET[‘oauth_token’]);
$token = $twitterObj->getAccessToken(array(‘oauth_verifier’ => $_GET[‘oauth_verifier’]));
$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
$_SESSION[‘ot’] = $token->oauth_token;
$_SESSION[‘ots’] = $token->oauth_token_secret;
$twitterInfo= $twitterObj->get_accountVerify_credentials();
$twitterInfo->response;

	echo '<pre>';
	print_r($twitterInfo->response);
</code>

Please suggest me solution for this.

Thanks


#2

I have the same problem…I used TweetSharp Library
try
{
if (!Page.IsPostBack)
{
if (Request.QueryString[“oauth_token”] != null && Request.QueryString[“oauth_verifier”] != null)
{
string x = Request.QueryString[“oauth_token”];
string y = Request.QueryString[“oauth_verifier”];

                    OAuthRequestToken requestToken = new OAuthRequestToken();

                    requestToken.Token = Request.QueryString["oauth_token"];
                    
                    string oauth_verifier = Request.QueryString["oauth_verifier"];
                    TwitterService service = new TwitterService(_consumerKey, _consumerSecret);
                    // HERE COME THE PROBLEM. (GetAccessToken)

OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier);
if (accessToken != null)
{
service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
TwitterUser user = service.VerifyCredentials(new VerifyCredentialsOptions());
Session[“uuuId”] = user.Id;
Session[“uuuScreenName”] = user.ScreenName;
Session[“uuuProfileImageUrl”] = user.ProfileImageUrl;

                        this.Master.logStatus.Text = user.ScreenName;
                        this.Master.logStatusImage.ImageUrl = user.ProfileImageUrl;

                        db = new TwitterLDataContext();
                        var checkUserVerify = from uu in db.NerdTwitterUsers
                                              where uu.Id == user.Id
                                              select user.Id;


                        getTweetsTimeLine(user.Id);


                        if (checkUserVerify.Count() == 0)
                        {
                            UTable = new NerdTwitterUser();
                            UTable.Id = user.Id;
                            UTable.IsVerified = (bool)user.IsVerified;
                            UTable.Name = user.Name;
                            UTable.ProfileImageUrl = user.ProfileImageUrl;
                            UTable.ScreenName = user.ScreenName;
                            UTable.Token = accessToken.Token;
                            UTable.TokenSecret = accessToken.TokenSecret;
                            db.NerdTwitterUsers.InsertOnSubmit(UTable);
                            db.SubmitChanges();
                        }
                    }
                    else {
                        ClientScriptManager cs = Page.ClientScript;
                        cs.RegisterStartupScript(this.GetType(), "Alert", "alert('El valor del AccesToken es NULO. Clic en Login nuevamente.');", true);                                                       
                    }
                }
            }
            else
            {
                if (Session["uuuScreenName"] != null)
                {

                    
                    this.Master.logStatus.Text = Session["uuuScreenName"].ToString();
                    this.Master.logStatusImage.ImageUrl = Session["uuuProfileImageUrl"].ToString();
                }
            }
        }
        catch (Exception exe)
        {
            string msg = exe.Message;

            ClientScriptManager cs = Page.ClientScript;                                
            cs.RegisterStartupScript(this.GetType(), "Alert", "alert('" +  msg + "');", true);                
        }