本文整理匯總了PHP中Twitter::getAccessToken方法的典型用法代碼示例。如果您正苦於以下問題:PHP Twitter::getAccessToken方法的具體用法?PHP Twitter::getAccessToken怎麽用?PHP Twitter::getAccessToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Twitter
的用法示例。
在下文中一共展示了Twitter::getAccessToken方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: twitterCallback
public function twitterCallback()
{
if (Session::has('oauth_request_token')) {
$request_token = array('token' => Session::get('oauth_request_token'), 'secret' => Session::get('oauth_request_token_secret'));
Twitter::set_new_config($request_token);
$oauth_verifier = FALSE;
if (Input::has('oauth_verifier')) {
$oauth_verifier = Input::get('oauth_verifier');
}
// getAccessToken() will reset the token for you
$token = Twitter::getAccessToken($oauth_verifier);
if (!isset($token['oauth_token_secret'])) {
return Redirect::to('/')->with('flash_error', 'We could not log you in on Twitter.');
}
$credentials = Twitter::query('account/verify_credentials');
if (is_object($credentials) && !isset($credentials->error)) {
// $credentials contains the Twitter user object with all the info about the user.
// Add here your own user logic, store profiles, create new users on your tables...you name it!
// Typically you'll want to store at least, user id, name and access tokens
// if you want to be able to call the API on behalf of your users.
// This is also the moment to log in your users if you're using Laravel's Auth class
// Auth::login($user) should do the trick.
return Redirect::to('/')->with('flash_notice', "Congrats! You've successfully signed in!");
}
return Redirect::to('/')->with('flash_error', 'Crab! Something went wrong while signing you up!');
}
}
示例2: callback
/**
* Good news from Twitter
*/
function callback()
{
if (!isset($_GET['oauth_token'])) {
throw new Exception();
}
$twitter = new Twitter();
$twitter->setToken($_GET['oauth_token']);
$token = $twitter->getAccessToken();
return $this->login_with_oauth($token->oauth_token, $token->oauth_token_secret);
}
示例3: callback
public function callback(Request $request)
{
// 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')];
Tweet::reconfig($request_token);
$oauth_verifier = false;
if ($request->has('oauth_verifier')) {
$oauth_verifier = $request->input('oauth_verifier');
}
// getAccessToken() will reset the token for you
$token = Tweet::getAccessToken($oauth_verifier);
if (!isset($token['oauth_token_secret'])) {
return redirect()->route('twitter.login')->with('flash_error', 'We could not log you in on Twitter.');
}
$credentials = Tweet::getCredentials();
if (is_object($credentials) && !isset($credentials->error)) {
// $credentials contains the Twitter user object with all the info about the user.
// Add here your own user logic, store profiles, create new users on your tables...you name it!
// Typically you'll want to store at least, user id, name and access tokens
// if you want to be able to call the API on behalf of your users.
// This is also the moment to log in your users if you're using Laravel's Auth class
// Auth::login($user) should do the trick.
Auth::user()->update(['bio' => $credentials->description, 'twitter' => $credentials->screen_name]);
$profile_image_url = file_get_contents(str_replace('_normal', '', $credentials->profile_image_url));
$profile_banner_url = file_get_contents($credentials->profile_banner_url);
$destinationPath = 'uploads/twitter';
$profile_image = $destinationPath . '/twitter_profile_' . $credentials->screen_name . '.jpg';
$profile_banner = $destinationPath . '/twitter_banner_' . $credentials->screen_name . '.jpg';
file_put_contents($profile_image, $profile_image_url);
file_put_contents($profile_banner, $profile_banner_url);
$file1 = File::create(['url' => $profile_image, 'original_name' => 'twitter_profile_' . $credentials->screen_name, 'type' => 'profile_photo']);
$file2 = File::create(['url' => $profile_banner, 'original_name' => 'twitter_banner_' . $credentials->screen_name, 'type' => 'profile_cover']);
Auth::user()->files()->sync([$file1->id, $file2->id]);
$twitter = Twitter::first();
$twitter_data = ['user_id' => Auth::user()->id, 'token' => $token['oauth_token'], 'secret' => $token['oauth_token_secret'], 'twitter_id' => $token['user_id'], 'screen_name' => $token['screen_name']];
is_null($twitter) ? Twitter::create($twitter_data) : Twitter::update($twitter_data);
session()->put('access_token', $token);
return redirect('admin/settings?tab=networks')->with('flash_notice', 'Congrats! You\'ve successfully signed in!');
}
return redirect()->route('twitter.error')->with('flash_error', 'Crab! Something went wrong while signing you up!');
}
}
示例4: function
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);
$oauth_verifier = false;
if (Input::has('oauth_verifier')) {
$oauth_verifier = Input::get('oauth_verifier');
}
// getAccessToken() will reset the token for you
$token = Twitter::getAccessToken($oauth_verifier);
if (!isset($token['oauth_token_secret'])) {
return Redirect::route('twitter.login')->with('flash_error', 'We could not log you in on Twitter.');
}
$credentials = Twitter::getCredentials();
if (is_object($credentials) && !isset($credentials->error)) {
// $credentials contains the Twitter user object with all the info about the user.
// Add here your own user logic, store profiles, create new users on your tables...you name it!
// Typically you'll want to store at least, user id, name and access tokens
// if you want to be able to call the API on behalf of your users.
// This is also the moment to log in your users if you're using Laravel's Auth class
// Auth::login($user) should do the trick.
Session::put('access_token', $token);
return Redirect::to('/')->with('flash_notice', 'Congrats! You\'ve successfully signed in!');
}
return Redirect::route('twitter.error')->with('flash_error', 'Crab! Something went wrong while signing you up!');
示例5: Twitter
$consoleObj->select($_GET['cID']);
if (!$member->hasAccess($consoleObj)) {
exit;
}
}
if (trim($_SERVER['HTTPS']) == "" || $_SERVER['HTTPS'] == "off") {
$dispHTTP = "http://";
} else {
$dispHTTP = "https://";
}
include_once "../plugins/twitter/twitter.php";
$twitterObj = new Twitter($mysqli);
if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier']) && $_GET['oauth_token'] == $_SESSION['btOauth_Token'] && !$twitterObj->hasTwitter($memberInfo['member_id'])) {
// CALLBACK
$twitterObj->oauthTokenSecret = $_SESSION['btOauth_Token_Secret'];
$response = $twitterObj->getAccessToken($_GET['oauth_token'], $_GET['oauth_verifier']);
if ($twitterObj->httpCode == 200) {
parse_str($response, $oauthArray);
$arrColumns = array("member_id", "oauth_token", "oauth_tokensecret", "loginhash");
$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";
示例6: serialize
}
// Set previously retreived tokens.
if (isset($_SESSION['request'])) {
$twitter->setRequest(unserialize($_SESSION['request']));
}
if (isset($_SESSION['access'])) {
$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.';
}
}
示例7: twitterCallback
public function twitterCallback()
{
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);
$oauth_verifier = false;
if (\Input::has('oauth_verifier')) {
$oauth_verifier = \Input::get('oauth_verifier');
}
// getAccessToken() will reset the token for you
$token = \Twitter::getAccessToken($oauth_verifier);
if (!isset($token['oauth_token_secret'])) {
return \Redirect::route('twitter.login')->with('flash_error', 'We could not log you in on Twitter.');
}
$credentials = \Twitter::getCredentials();
if (is_object($credentials) && !isset($credentials->error)) {
$newonee = new \App\Repositories\UserRepository();
$user = $newonee->findByUsernameOrCreate2($credentials);
\Auth::login($user);
\Session::put('access_token', $token);
return \Redirect::to('/')->with('flash_notice', 'Congrats! You\'ve successfully signed in!');
}
return \Redirect::route('twitter.error')->with('flash_error', 'Crab! Something went wrong while signing you up!');
}
}