本文整理匯總了PHP中Twitter::getRequestToken方法的典型用法代碼示例。如果您正苦於以下問題:PHP Twitter::getRequestToken方法的具體用法?PHP Twitter::getRequestToken怎麽用?PHP Twitter::getRequestToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Twitter
的用法示例。
在下文中一共展示了Twitter::getRequestToken方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: login
public function login()
{
// your SIGN IN WITH TWITTER button should point to this route
$sign_in_twitter = true;
$force_login = false;
// Make sure we make this request w/o tokens, overwrite the default values in case of login.
Tweet::reconfig(['token' => '', 'secret' => '']);
$token = Tweet::getRequestToken(route('twitter.callback'));
if (isset($token['oauth_token_secret'])) {
$url = Tweet::getAuthorizeURL($token, $sign_in_twitter, $force_login);
session()->put('oauth_state', 'start');
session()->put('oauth_request_token', $token['oauth_token']);
session()->put('oauth_request_token_secret', $token['oauth_token_secret']);
return redirect($url);
}
return redirect()->route('twitter.error');
}
示例2: function
}
return $output;
});
Route::post('sendtweet', function () {
$file = file_get_contents(Input::get('image'));
$file = base64_encode($file);
$uploaded_media = Twitter::uploadMedia(['media_data' => $file]);
return Twitter::postTweet(['status' => Input::get('text'), 'media_ids' => $uploaded_media->media_id_string]);
});
Route::get('twitter/login', ['as' => 'twitter.login', function () {
// your SIGN IN WITH TWITTER button should point to this route
$sign_in_twitter = true;
$force_login = false;
// Make sure we make this request w/o tokens, overwrite the default values in case of login.
Twitter::reconfig(['token' => '', 'secret' => '']);
$token = Twitter::getRequestToken(route('twitter.callback'));
if (isset($token['oauth_token_secret'])) {
$url = Twitter::getAuthorizeURL($token, $sign_in_twitter, $force_login);
Session::put('oauth_state', 'start');
Session::put('oauth_request_token', $token['oauth_token']);
Session::put('oauth_request_token_secret', $token['oauth_token_secret']);
return Redirect::to($url);
}
return Redirect::route('twitter.error');
}]);
Route::get('twitter/callback', ['as' => 'twitter.callback', function () {
// You should set this route on your Twitter Application settings as the callback
// https://apps.twitter.com/app/YOUR-APP-ID/settings
if (Session::has('oauth_request_token')) {
$request_token = ['token' => Session::get('oauth_request_token'), 'secret' => Session::get('oauth_request_token_secret')];
Twitter::reconfig($request_token);
示例3: array
$arrValues = array($memberInfo['member_id'], $oauthArray['oauth_token'], $oauthArray['oauth_token_secret'], md5($oauthArray['oauth_token']));
if (!$twitterObj->authorizeLogin($oauthArray['oauth_token'], $oauthArray['oauth_token_secret'])) {
$twitterObj->addNew($arrColumns, $arrValues);
echo "\n\t\t\t\t<script type='text/javascript'>\n\t\t\t\t\twindow.location = '" . $MAIN_ROOT . "members/console.php?cID=" . $_GET['cID'] . "';\n\t\t\t\t</script>\n\t\t\t";
} else {
echo "\n\t\t\t\n\t\t\t\t<div class='shadedBox' style='margin-left: auto; margin-right: auto; width: 50%'>\n\t\t\t\t\t<p class='main' align='center'>\n\t\t\t\t\t\tThe chosen twitter account is already associated with a member on this site!<br><br>\n\t\t\t\t\t\t<a href='" . $MAIN_ROOT . "members/console.php?cID=" . $_GET['cID'] . "'>Retry</a>\n\t\t\t\t\t</p>\n\t\t\t\t</div>\n\t\t\t\n\t\t\t";
}
} else {
echo "\n\t\t\n\t\t\t<div class='shadedBox' style='margin-left: auto; margin-right: auto; width: 50%'>\n\t\t\t\t<p class='main' align='center'>\n\t\t\t\t\tUnable to connect account! Please Try Again.<br><br>\n\t\t\t\t\t<a href='" . $MAIN_ROOT . "members/console.php?cID=" . $_GET['cID'] . "'>Retry</a>\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t\n\t\t";
}
} elseif (isset($_GET['denied'])) {
echo "\n\t\t<script type='text/javascript'>\n\t\t\twindow.location = '" . $MAIN_ROOT . "members';\n\t\t</script>\n\t";
exit;
} elseif (!$twitterObj->hasTwitter($memberInfo['member_id'])) {
// CONNECT
$response = $twitterObj->getRequestToken($dispHTTP . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
$twitterObj->hasTwitter($memberInfo['member_id']);
if ($response !== false) {
parse_str($response, $arrOutput);
$_SESSION['btOauth_Token'] = $arrOutput['oauth_token'];
$_SESSION['btOauth_Token_Secret'] = $arrOutput['oauth_token_secret'];
echo "\n\t\t\t\t\t\n\t\t\t<p>Redirecting to Twitter...</p>\n\t\t\t<script type='text/javascript'>\n\t\t\t\n\t\t\t\twindow.location = '" . $twitterObj->authorizeURL . "?oauth_token=" . $arrOutput['oauth_token'] . "';\n\t\t\t\n\t\t\t</script>\n\n\t\t";
} else {
echo "\n\t\t\t\n\t\t\t<div class='shadedBox' style='margin-left: auto; margin-right: auto; width: 50%'>\n\t\t\t\t<p class='main' align='center'>\n\t\t\t\t\tUnable to connect account! Please Try Again.<br><br>\n\t\t\t\t\t<a href='" . $MAIN_ROOT . "members/console.php?cID=" . $_GET['cID'] . "'>Retry</a>\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t\n\t\t";
}
} elseif ($twitterObj->hasTwitter($memberInfo['member_id'])) {
$dispSuccess = false;
if ($_POST['submit']) {
$setShowFeed = $_POST['showfeed'] == 1 ? 1 : 0;
$setEmbedTweet = $_POST['embedlasttweet'] == 1 ? 1 : 0;
$setInfoCard = $_POST['showinfo'] == 1 ? 1 : 0;
示例4: serialize
$twitter->setAccess(unserialize($_SESSION['access']));
}
// Check to see if we have access tokens.
if (!$twitter->hasAccess()) {
// We don't yet have access. Let's see if we can get it.
if (isset($_GET['denied'])) {
echo 'The user has denied access to your application.';
} else {
// Check to see if we can get an access token.
if ($access = $twitter->getAccessToken()) {
$_SESSION['access'] = serialize($access);
header("Location: " . $twitter->getOAuthCallback(), true, 301);
die('<a href="' . $twitter->getOAuthCallback() . '">Complete Login</a>');
} else {
// Unable to get access token. We'll settle for a request token instead.
$request = $twitter->getRequestToken();
if ($request) {
$_SESSION['request'] = serialize($request);
// Display or redirect to user to their login URL.
echo '<a href="' . $twitter->getLoginURL() . '">' . $twitter->getLoginURL() . '</a>';
} else {
// Problems.
echo 'Unable to get request token.';
}
}
}
} else {
// The user has authorized access to the application.
// Get the current user.
$user = $twitter->getUser();
/**
示例5: twitterLogin
public function twitterLogin(AuthenticateUser $authenticateUser, Request $request)
{
$sign_in_twitter = true;
$force_login = true;
\Twitter::reconfig(['token' => '', 'secret' => '']);
$token = \Twitter::getRequestToken(route('twitter.callback'));
if (isset($token['oauth_token_secret'])) {
$url = \Twitter::getAuthorizeURL($token, $sign_in_twitter, $force_login);
\Session::put('oauth_state', 'start');
\Session::put('oauth_request_token', $token['oauth_token']);
\Session::put('oauth_request_token_secret', $token['oauth_token_secret']);
return \Redirect::to($url);
}
return \Redirect::route('twitter.error');
}