本文整理汇总了PHP中Facebook\Facebook::getUser方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::getUser方法的具体用法?PHP Facebook::getUser怎么用?PHP Facebook::getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook\Facebook
的用法示例。
在下文中一共展示了Facebook::getUser方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callback
public function callback()
{
$code = Input::get('code');
if (strlen($code) == 0) {
return \Redirect::to('/');
}
$facebook = new Facebook(\Config::get('facebook'));
$uid = $facebook->getUser();
if ($uid == 0) {
return \Redirect::to('/');
}
$me = $facebook->api('/me');
$profile = User::where('user_id', $uid)->first();
if (empty($profile)) {
$user = new User();
$user->username = $me['name'];
$user->photo = 'https://graph.facebook.com/' . $me['id'] . '/picture?type=large';
$user->user_id = $uid;
$user->save();
$x = new leaderboard();
$x->user_id = $uid;
$x->user_name = $me['name'];
$x->round_id = 1;
$x->save();
}
$user = User::where('user_id', $uid)->select('user_id', 'username', 'photo')->first();
session()->put(['user_id' => $uid, 'name' => $user['username']]);
return redirect('/');
}
示例2: Facebook
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
use Facebook\Facebook;
use Facebook\FacebookApiException;
require '../src/Facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array('appId' => '344617158898614', 'secret' => '6dc8ac871858b34798bc2488200e503d'));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
示例3: renderLogin
/**
* Generate and print the rendered login markup to STDOUT.
*
* @param array $form_options
*
* @return void
*/
public function renderLogin($form_options = [])
{
if (!FACEBOOK_APP_ID) {
echo 'Please configure Facebook with your APP_ID.';
return;
}
if (!FACEBOOK_APP_SECRET) {
echo 'Please configure Facebook with your APP_SECRET.';
return;
}
$facebook = new \Facebook(['appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_APP_SECRET]);
// User was already logged in.
try {
$user = $facebook->getUser();
if ($user) {
$user_profile = $facebook->api('/me');
$facebooklink = false;
} else {
$facebooklink = $facebook->getLoginUrl();
}
} catch (\Exception $c) {
$facebooklink = $facebook->getLoginUrl();
}
// $logoutUrl = $facebook->getLogoutUrl();
$tpl = \Core\Templates\Template::Factory('includes/user/facebook_login.tpl');
$tpl->assign('facebooklink', $facebooklink);
$tpl->render();
}