Hi,

we are using the below code to make api call
The api call to fetch tweet is not working but api call for credential
is working fine.

It is showing the below error

{"request":"\/1\/statuses\/retweets_of_me.json?","error":"Could not
authenticate you."}


Please see the below code
----------------------------------------------------------------------------------------------------------------------------------------

        define('CONSUMER_KEY', $param['CONSUMER_KEY']);
                define('CONSUMER_SECRET',$param['CONSUMER_SECRET']);
                define('OAUTH_CALLBACK', $param['OAUTH_CALLBACK']);


                if(!isset($_SESSION['oauth_token']) ||
empty($_SESSION['oauth_token'])){
                        /* 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);

                                break;
                          default:
                                /* Show notification if something went wrong. */
                                echo 'Could not connect to Twitter. Refresh the 
page or try again
later.';
                        }
                }

                
//////////////////////////////////////////////////////////////////////////////
                /* Create TwitteroAuth object with app key/secret and token key/
secret from default phase */
                $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

                /* Request access tokens from twitter */
                $access_token = $connection-
>getAccessToken($_REQUEST['oauth_verifier']);

                /* Save the access tokens. Normally these would be saved in a
database for future use. */
                $_SESSION['access_token'] = $access_token;



                /* If HTTP response is 200 continue otherwise send to connect 
page
to retry */
                if (200 == $connection->http_code) {

                        /* The user has been verified and the access tokens can 
be saved
for future use */
                        $_SESSION['status'] = 'verified';

                        /* Get user access tokens out of the session. */
                        $access_token = $_SESSION['access_token'];

                        /* Create a TwitterOauth object with consumer/user 
tokens. */
                        $connection = new TwitterOAuth(CONSUMER_KEY, 
CONSUMER_SECRET,
$access_token['oauth_token'], $access_token['oauth_token_secret']);

                        /* If method is set change API call made. Test is 
called by
default. */
                        $content = 
$connection->get('account/verify_credentials');

                 $api = 'http://api.twitter.com/1/statuses/
retweets_of_me.json';

                // twitter follower api
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $api);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $content= curl_exec($ch);
                curl_close($ch);
               print_r($content);
                        session_destroy();

                        return $content;

                } else {

                         /* Save HTTP status for error dialog on connnect 
page.*/
                        if($this->debug){
                                echo $connection->http_code. ' invalid response 
code. <br/>';
                        }
                        return false;
                }

-- 
Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 
http://groups.google.com/group/twitter-development-talk

Reply via email to