Web Analytics Made Easy -
StatCounter Need help in Twitter api (Abraham's TwitterOAuth: Could Not Authenticate You Problem) - CodingForum

Announcement

Collapse
No announcement yet.

Need help in Twitter api (Abraham's TwitterOAuth: Could Not Authenticate You Problem)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved Need help in Twitter api (Abraham's TwitterOAuth: Could Not Authenticate You Problem)

    Well,

    I am using Abraham's TwitterOauth library to build an application that will collect oauth token and oauth token secret for each user and save it to database. So that later I can tweet on behalf of them.

    I am doing it correctly. When user clicks on Allow this Application my app is getting authorized and user is redirected to the callback. I am also getting the Oauth token and Oauth token secret. But it's not working when it comes to update status or read timeline or do anything else with user's account.

    I have read and write access in settings. My consumer keys and secret are correct.

    It says Could Not Authenticate You.. What might be the problem? Please see my code below-

    Here is the code for index.php (URL for the application):

    PHP Code:
    <?php
    session_start
    ();
    require_once 
    'twitteroauth.php';
    require_once 
    'OAuth.php';
    define("CONSUMER_KEY""My key here");
    define("CONSUMER_SECRET""my secret here");
    $to = new TwitterOAuth(CONSUMER_KEYCONSUMER_SECRET);
    $tok $to->getRequestToken($_REQUEST['oauth_verifier']);
    $request_link $to->getAuthorizeURL($tok);
    $_SESSION['oauth_access_token']= $tok['oauth_token'];
    $_SESSION['oauth_access_token_secret'] = $tok['oauth_token_secret'];
    header("Location: $request_link");
    exit;
    ?>
    Code For callback.php:

    PHP Code:
    <?php
    session_start
    ();
    require_once 
    'twitteroauth.php';
    require_once 
    'OAuth.php';
    define("CONSUMER_KEY""My Key");
    define("CONSUMER_SECRET""My Secret");
    if ((!isset(
    $_SESSION['oauth_access_token'])) || ($_SESSION['oauth_access_token'])==''
    {
    $to = new TwitterOAuth(CONSUMER_KEYCONSUMER_SECRET$_SESSION['oauth_request_token'], $_SESSION['oauth_request_token_secret']);
    $token_credentials $to->getAccessToken($_REQUEST['oauth_verifier']);
    $_SESSION['oauth_access_token'] =$token_credentials['oauth_token'];
    $_SESSION['oauth_access_token_secret'] = $token_credentials['oauth_token_secret'];
    }
    $to=new TwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET,$_SESSION['oauth_access_token'],$_SESSION['oauth_access_token_secret']);
    $content $to->post('statuses/update', array('status' => 'Hello Twitter')); 
    var_dump($content);
    ?>
    It gives the following Output:

    object(stdClass)#5 (2) { ["error"]=> string(27) "Could not authenticate you." ["request"]=> string(23) "/1/statuses/update.json" }

    It says "Could Not Authenticate You"...

    Any help will be highly appreciated..

    Thanks A Lot!
    Last edited by Inigoesdr; Aug 26, 2011, 03:27 PM.

  • #2
    Got the solution...

    Comment

    Working...
    X