[英]PHP OAuth Twitter
I have created a twitter app which I am using to post tweets. 我创建了一个Twitter应用程序,用于发布推文。 The problem that I am not able to resolve is everytime I have to allow access to my application.
我无法解决的问题是每次我必须允许访问我的应用程序时。
so lets say I need to tweet three messages, so all the three times I have to allow access to my app. 假设我需要发布3条消息,所以这3次都必须允许我访问我的应用。
I just need that once user has allowed access to my app, next time he should only be asked to allow acces is that when he/she relogins. 我只需要在用户允许访问我的应用程序后,下一次仅在他/她重新登录时才被要求允许访问权限。
Here's my code that I am using 这是我正在使用的代码
Share content on twitter"; include 'lib/EpiCurl.php'; include 'lib/EpiOAuth.php'; include 'lib/EpiTwitter.php'; include 'lib/secret.php'; $twitterObj = new EpiTwitter($consumer_key, $consumer_secret); $oauth_token = $_GET['oauth_token']; if($oauth_token == '') { $url = $twitterObj->getAuthorizationUrl(); echo ""; echo "Sign In with Twitter"; echo ""; } else { $twitterObj->setToken($_GET['oauth_token']); $token = $twitterObj->getAccessToken(); $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; $username = $twitterInfo->screen_name; $profilepic = $twitterInfo->profile_image_url; include 'update.php'; } if(isset($_POST['submit'])) { $msg = $_REQUEST['tweet']; $twitterObj->setToken($_SESSION['ot'], $_SESSION['ots']); $update_status = $twitterObj->post_statusesUpdate(array('status' => $msg)); $temp = $update_status->response; header("Location: MessageStatus.html"); exit(); } ?>
Share content on twitter"; include 'lib/EpiCurl.php'; include 'lib/EpiOAuth.php'; include 'lib/EpiTwitter.php'; include 'lib/secret.php'; $twitterObj = new EpiTwitter($consumer_key, $consumer_secret); $oauth_token = empty($_SESSION['ot']) ? $_GET['oauth_token']:$_SESSION['ot']; if($oauth_token == '') { $url = $twitterObj->getAuthorizationUrl(); echo ""; echo "Sign In with Twitter"; echo ""; } else { if(empty($_SESSION['ot'])) { $twitterObj->setToken($_GET['oauth_token']); $token = $twitterObj->getAccessToken(); $twitterObj->setToken($token->oauth_token, $token->oauth_token_secret); $_SESSION['ot'] = $token->oauth_token; $_SESSION['ots'] = $token->oauth_token_secret; } else { $twitterObj->setToken($_SESSION['ot'], $_SESSION['ots']); } $twitterInfo= $twitterObj->get_accountVerify_credentials(); $twitterInfo->response; $username = $twitterInfo->screen_name; $profilepic = $twitterInfo->profile_image_url; include 'update.php'; } if(isset($_POST['submit'])) { $msg = $_REQUEST['tweet']; try { $twitterObj->setToken($_SESSION['ot'], $_SESSION['ots']); $update_status = $twitterObj->post_statusesUpdate(array('status' => $msg)); $temp = $update_status->response; } catch (Exception $e) { } } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.