Re: [twitter-dev] Re: Twiiter Latest 20 Tweets requires authorization

2011-03-22 Thread Abraham Williams
I just posted an answer in the other thread you started:
https://groups.google.com/forum/#!topic/twitter-development-talk/JE_N9nzJI9c

Abraham
-
Abraham Williams | Hacker Advocate | abrah.am
Just launched from Answerly :
InboxQfor Chrome
@abraham  | github.com/abraham | blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.



On Tue, Mar 22, 2011 at 01:47, deepak  wrote:

> Hi
> i am using the below code
>but it is still showing me error for authentication
>but user credential call is working fine.
>
>  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');
>
>// Twitter re tweet api call
>   $api = 'http://api.twitter.com/1/statuses/
> retweets_of_me.json';
>// request 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. ';
>}
>return false;
>}
>
> On Mar 22, 1:18 pm, CWorster  wrote:
> > Here are some OAuth Libraries in PHPhttp://
> dev.twitter.com/pages/oauth_libraries#php
> >
> > 2011/3/22 deepak :
> >
> > > Hi,
> >
> > > We are displaying twitter latest 20 tweets to me on my website.
> > > but th

[twitter-dev] Re: Twiiter Latest 20 Tweets requires authorization

2011-03-22 Thread deepak
Hi
 i am using the below code
but it is still showing me error for authentication
but user credential call is working fine.

  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');

// Twitter re tweet api call
   $api = 'http://api.twitter.com/1/statuses/
retweets_of_me.json';
// request 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. ';
}
return false;
}

On Mar 22, 1:18 pm, CWorster  wrote:
> Here are some OAuth Libraries in 
> PHPhttp://dev.twitter.com/pages/oauth_libraries#php
>
> 2011/3/22 deepak :
>
> > Hi,
>
> > We are displaying twitter latest 20 tweets to me on my website.
> > but this api call requires authorization and we have not found any
> > code for authorization using php.
>
> > we have read the full documentation of oauth on dev.twitter.com but
> > still when we access
> >http://api.twitter.com/1/statuses/retweets_to_me.json
>
> > it shows error message {"request":"\/1\/statuses\/retweets_of_me.json?
> > count=100&page=1&trim_user=true&include_entities=true","error":"Could
> > not authenticate you."}.
>
> > Please provide authorization code for api call.
>
> > Please help me to solve this issue.
>
> > Thanks
>
> > --
> > Twitter developer documentation and resources:http://dev.twitter.com/doc
>