How do I sign-in on twitter by php script? (I don't want to use the login page) I use PHP/OAuth (http://github.com/abraham/twitteroauth). I would like to login (by php) to use in automatically another Twitter-application.
how can I retrieve 'access_token' & 'oauth_token_secret'?
1) thank's but the problem is: "TEMPORARY credentials"...
Whenever the data changes. example:
/* first */
$request_token = $connection->getRequestToken('http://www.xxxxxxxxxxx.php');
echo $request_token['oauth_token']."<br>"; /* == 1213hfktyititff */
echo $request_token['oauth_token_secret']."<br>"; /开发者_如何转开发* == ttjkhklkutltu */
/* second*/
$request_token = $connection->getRequestToken('http://www.xxxxxxxxxxx.php');
echo $request_token['oauth_token']."<br>"; /* == kjregntrury89r */
echo $request_token['oauth_token_secret']."<br>"; /* == 87r86rbw7brywgewgwr */
2)thanks but I would like to use an application of another person => I do not have infinite lifetime for my oauth_token & secret :(
This should do what you need:
<?php
require_once('twitteroauth.php');
/* Application Details */
$connection = new TwitterOAuth("----Your Consumer Key -----",
"------------Consumer Secret-------------");
/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
/* Save temporary credentials to session. */
$token = $request_token['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);
echo"<a href='". $url."'>Login With Twitter </a>";
break;
default:
/* Show notification if something went wrong. */
echo 'Could not connect to Twitter. Refresh the page or try again later.';
}
?>
how can I retrieve 'access_token' & 'oauth_token_secret'?
You should register your application/website here. You'll be given app id and app secret. After that you get a token by using code
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
$token = $request_token['oauth_token'];
$secret= $request_token['oauth_token_secret'];
As EdoDodo said
精彩评论